我有一个简单的折线图 MPAndroidChart library :
chart.setDrawYValues(false);
chart.setDescription("");
chart.setDrawVerticalGrid(true);
chart.setDrawGridBackground(false);
XLabels xl = holder.chart.getXLabels();
xl.setCenterXLabelText(true);
xl.setPosition(XLabelPosition.BOTTOM);
YLabels yl = holder.chart.getYLabels();
yl.setLabelCount(5);
// set data
chart.setData((LineData) mChartData);
chart.setDrawYValues(true);
chart.setValueTextSize(20f);
// zooming on both axis
chart.setPinchZoom(true);
chart.animateX(1000);
但是我有一个可视化问题。 X 轴上的标签不在相对网格线之下,而是在两条线之间(在 Y 轴上我没有这个问题)。有没有办法将 Y 标签正好放在相对网格线的下方?
最佳答案
调用这个:
XLabels xl = chart.getXLabels();
xl.setCenterXLabelText(true);
将导致标签绘制在两行之间。如果您调用 setCenterXLabelText(false);
,标签应该恰好位于各个网格线的上方。
同时检查示例项目 LineChart
。那里的标签正好在线条上方。
更新
3.1.0 版本中没有getXLabels
方法。使用这个:
chart.xAxis.setCenterAxisLabels(true)
关于android - MPAndroidChart,如何使 XLabels 在网格线上方居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26715020/