MPAndroid 图表。在条形图中,我有重复的背景线
MPAndroidChart. In BarChart i have duplicate background lines
我使用 MPAndroidChart 创建了 BarChart,并通过以下代码删除了正确的 YAxis 标签:
mBarChart.getAxisRight().setDrawLabels(false);
在此之后,我的背景线变得重复
之前:
这是我现在拥有的:
我的代码:
//barChart
mBarChart.setDrawBarShadow(false);
mBarChart.setDrawValueAboveBar(true);
mBarChart.setDescription("");
// if more than 60 entries are displayed in the chart, no values will be
// drawn
mBarChart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
mBarChart.setPinchZoom(true);
// draw shadows for each bar that show the maximum value
mBarChart.setDrawBarShadow(false);
mBarChart.animateY(2000, Easing.EasingOption.EaseInQuart);
// mChart.setDrawXLabels(false);
mBarChart.setDrawGridBackground(false);
//mBarChart.setDrawYLabels(false);
XAxis xAxis = mBarChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setTypeface(tf);
xAxis.setDrawGridLines(false);
xAxis.setSpaceBetweenLabels(2);
ValueFormatter custom = new MyValueFormatter();
YAxis leftAxis = mBarChart.getAxisLeft();
leftAxis.setTypeface(tf);
leftAxis.setLabelCount(6);
leftAxis.setValueFormatter(custom);
leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
leftAxis.setSpaceTop(15f);
mBarChart.getAxisRight().setDrawLabels(false);
/*YAxis rightAxis = mBarChart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setTypeface(tf);
rightAxis.setLabelCount(8);
rightAxis.setValueFormatter(custom);
rightAxis.setSpaceTop(15f);*/
Legend legend = mBarChart.getLegend();
legend.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT);
legend.setForm(Legend.LegendForm.SQUARE);
legend.setFormSize(9f);
legend.setTextSize(11f);
legend.setXEntrySpace(4f);
/* legend.setExtra(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
"def", "ghj", "ikl", "mno" });
legend.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
"def", "ghj", "ikl", "mno" });*/
setDataToBarChart(mParties.size(), 50);
原因是右轴没有被禁用,但只有它的标签被隐藏,并且您有不同的设置(顶部-space、字体和标签计数)导致线条在不同的地方。
为防止这种情况发生,请致电rightAxis.setEnabled(false)
。这将禁用整个轴并且不再导致您的问题。
我使用 MPAndroidChart 创建了 BarChart,并通过以下代码删除了正确的 YAxis 标签:
mBarChart.getAxisRight().setDrawLabels(false);
在此之后,我的背景线变得重复
之前:
这是我现在拥有的:
我的代码:
//barChart
mBarChart.setDrawBarShadow(false);
mBarChart.setDrawValueAboveBar(true);
mBarChart.setDescription("");
// if more than 60 entries are displayed in the chart, no values will be
// drawn
mBarChart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
mBarChart.setPinchZoom(true);
// draw shadows for each bar that show the maximum value
mBarChart.setDrawBarShadow(false);
mBarChart.animateY(2000, Easing.EasingOption.EaseInQuart);
// mChart.setDrawXLabels(false);
mBarChart.setDrawGridBackground(false);
//mBarChart.setDrawYLabels(false);
XAxis xAxis = mBarChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setTypeface(tf);
xAxis.setDrawGridLines(false);
xAxis.setSpaceBetweenLabels(2);
ValueFormatter custom = new MyValueFormatter();
YAxis leftAxis = mBarChart.getAxisLeft();
leftAxis.setTypeface(tf);
leftAxis.setLabelCount(6);
leftAxis.setValueFormatter(custom);
leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
leftAxis.setSpaceTop(15f);
mBarChart.getAxisRight().setDrawLabels(false);
/*YAxis rightAxis = mBarChart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setTypeface(tf);
rightAxis.setLabelCount(8);
rightAxis.setValueFormatter(custom);
rightAxis.setSpaceTop(15f);*/
Legend legend = mBarChart.getLegend();
legend.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT);
legend.setForm(Legend.LegendForm.SQUARE);
legend.setFormSize(9f);
legend.setTextSize(11f);
legend.setXEntrySpace(4f);
/* legend.setExtra(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
"def", "ghj", "ikl", "mno" });
legend.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
"def", "ghj", "ikl", "mno" });*/
setDataToBarChart(mParties.size(), 50);
原因是右轴没有被禁用,但只有它的标签被隐藏,并且您有不同的设置(顶部-space、字体和标签计数)导致线条在不同的地方。
为防止这种情况发生,请致电rightAxis.setEnabled(false)
。这将禁用整个轴并且不再导致您的问题。