我想將我的酒吧值添加到酒吧的左側,並將酒吧標籤添加到酒吧的右側。MpAndroidChart HorizontalBarChart自定義標籤
下面是initilizes HorizontalBarChart
HorizontalBarChart mChart = (HorizontalBarChart) findViewById(R.id.chart1);
mChart.setOnChartValueSelectedListener(this);
mChart.setDrawBarShadow(false);
mChart.setDrawValueAboveBar(true);
mChart.setDescription(strHeading);
mChart.setMaxVisibleValueCount(60);
mChart.setPinchZoom(false);
mChart.setDrawGridBackground(false);
XAxis xl = mChart.getXAxis();
xl.setDrawLabels(false);
YAxis yl = mChart.getAxisLeft();
yl.setDrawLabels(false);
YAxis yr = mChart.getAxisRight();
yr.setTypeface(mTfLight);
yr.setDrawAxisLine(true);
yr.setDrawGridLines(false);
setData(12, 50);
mChart.setFitBars(true);
mChart.animateY(2500);
mChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE);
Legend l = mChart.getLegend();
l.setPosition(Legend.LegendPosition.ABOVE_CHART_LEFT);
l.setFormSize(8f);
l.setXEntrySpace(4f);
下面是結合的數據的方法,下面的代碼的代碼
float barWidth = 9f;
float spaceForBar = 10f;
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
for (int i=0 ; i< arrayChart.size(); i++){
ModelChart modelChart = arrayChart.get(i);
String aString = modelChart.getHeader();
float space = i * spaceForBar;
BarEntry eachEntry = new BarEntry(i * spaceForBar, modelChart.getValue() , modelChart.getHeader());
yVals1.add(eachEntry);
}
if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
BarDataSet set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0);
set1.setValues(yVals1);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
} else {
set1 = new BarDataSet(yVals1, "A , B , C");
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
BarData data = new BarData(dataSets);
data.setValueTextSize(10f);
data.setValueTypeface(mTfLight);
data.setBarWidth(barWidth);
mChart.setData(data);
}
它是你的自定義組件嗎? –
嗨@亞西爾阿里,我用HorizontalBarChart – Cloy
我檢查了庫代碼不容易,但我盡我所能解釋你。他們有HorizontalBarChartRenderer.java負責渲染你的條形圖和方法drawValues做這個文本渲染。你可以做什麼重寫此方法,並以某種方式覆蓋HorizontalBarChartRenderer和默認渲染器的HorizontalBarChart.init。 –