我使用来自github的MPandroid
图表库,这是我的应用程序中的lib链接MPANDROID来绘制一些图表,但问题是条的高度,我有 YValue1 = 81 , YValue2 = 97 , YValue3 = 91 , YValue = 86 但是条形图非常小!!
图片链接
private void setBarChart(BarChart mChart, DashboardMCOP mcop, DashboardMCOM mcom)
{
mChart.setOnChartValueSelectedListener(this);
mChart.setDrawBarShadow(false);
mChart.setDrawValueAboveBar(true);
mChart.getDescription().setEnabled(false);
mChart.setMaxVisibleValueCount(100);
mChart.setPinchZoom(false);
mChart.setDrawGridBackground(false);
IAxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(mChart,context );
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setGranularity(1f); // only intervals of 1 day
xAxis.setLabelCount(7);
xAxis.setValueFormatter(xAxisFormatter);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setEnabled(false);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setEnabled(false);
Legend l = mChart.getLegend();
l.setEnabled(false);
XYMarkerView mv = new XYMarkerView(context, xAxisFormatter);
mv.setChartView(mChart); // For bounds control
mChart.setMarker(mv); // Set the marker to the chart
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
setDataBar(mChart, mcop, mcom);
}
我在条形图中设置数据的功能
private void setDataBar(BarChart mChart, DashboardMCOP mcop, DashboardMCOM mcom)
{
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
int id = mChart.getId();
String viewName = getResources().getResourceEntryName(id);
if(viewName.equalsIgnoreCase("barchartMCOM1")) {
if(mcom != null) {
yVals1.add(new BarEntry(0, mcom.getTreat()));
yVals1.add(new BarEntry(1, mcom.getContract()));
}
}
BarDataSet set1 = null;
set1 = new BarDataSet(yVals1, "");
set1.setColors(ColorTemplate.rgb("#FF0000"));
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
BarData data = new BarData(dataSets);
data.setValueTextSize(10f);
data.setBarWidth(0.9f);
data.setValueFormatter(new MyAxisValueFormatter());
mChart.setFitBars(true);
mChart.setData(data);
mChart.invalidate();
}
答案 0 :(得分:0)
我从github更新lib,然后我使用示例BarChartFragment来解决问题,这是我在未来遇到同样问题的人的代码:
private void setBarChart(BarChart mChart, DashboardMCOP mcop, DashboardMCOM mcom)
{
mChart.getDescription().setEnabled(false);
MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
mv.setChartView(mChart); // For bounds control
mChart.setMarker(mv);
mChart.setMaxVisibleValueCount(100);
mChart.setDrawGridBackground(false);
mChart.setDrawBarShadow(false);
IAxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(mChart,context );
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setGranularity(1f); // only intervals of 1 day
xAxis.setLabelCount(7);
xAxis.setValueFormatter(xAxisFormatter);
Legend l = mChart.getLegend();
l.setEnabled(false);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
leftAxis.setEnabled(true);
leftAxis.setAxisMaximum(100);
mChart.getAxisRight().setEnabled(false);
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
setDataBar(mChart, mcop, mcom);
}
SetDataBar 的不是更改!