I'm using the library mpandroidchart
to plot a series of data on a line chart. The series is formed by point (x,y) where x represents the time (in seconds), and y represents a temperature.
(The x values are random, and so there is not a max common divisor).
My attempt. As you can see, the labels on the Y's axis are well displayed, with a step of 10 unit. This doesn't hold for the X's axis.
So, I would like to define the step for the labels on the X's axis how to do, but I have no idea, and it seems an unsupported setting by the library. Can you help me?
答案 0 :(得分:0)
您需要添加:
chart.getXAxis().setLabelsToSkip(10);
替换' 10'按您想要跳过的标签数量。
答案 1 :(得分:0)
您可以使用XAxisValueFormater
和setLabelsToSkip()
:
public class MyCustomXAxisValueFormatter implements XAxisValueFormatter {
@Override
public String getXValue(String original, int index, ViewPortHandler viewPortHandler) {
viewPortHandler.setMaximumScaleX(24f);
float scalex=viewPortHandler.getScaleX();
if(scalex>=2.6f && scalex <3f)
mChart.getXAxis().setLabelsToSkip(47);
if(scalex>=3f && scalex <4f)
mChart.getXAxis().setLabelsToSkip(35);
if(scalex>=4f && scalex <11f)
mChart.getXAxis().setLabelsToSkip(23);
if(scalex>=11f && scalex <18f)
mChart.getXAxis().setLabelsToSkip(11);
if(scalex>=18f && scalex <24f)
mChart.getXAxis().setLabelsToSkip(5);
return original;
}
}
根据放大或缩小图表的数量,设置应该滑动多少个X轴标签。
希望它有所帮助!