简体   繁体   中英

MPAndroidChart how to set the X scale

Day good comrades, I use the MPAndroidChart library to draw a linear chart of price changes depending on the time. With the Y scale, there were no problems, but I can not make the X scale work properly. There are waters that substitute in this scale the desired value depending on the position:

IAxisValueFormatter formatter = new IAxisValueFormatter() {
    @Override
    public String getFormattedValue(float value, AxisBase axis) {
        return quarters[(int) value];
    }
;
XAxis xAxis = mLineChart.getXAxis();
xAxis.setGranularity(1f);
xAxis.setValueFormatter(formatter);

But there is a problem, the schedule is sorted out at the end of loading by the loader, and the start time is the choice of the time period for which the user wants to see the result. If the result is to be seen in 10 minutes - then the server comes less than 10 values, if for a day, more than 100. And the problem is that why the value is not updated, and when after 100 values ​​I need to look back 10, it looks in the list of axes Y values ​​of 100, of course, does not find them because we only have 10 of them to crumble. Actually the question is how to reset these values? Before transferring data to the graph, I do mChart.clear (); but it does not help. I do not understand the dirty trick. Help to understand please.

In general, I decided this: I wrote my formatter and in it:

@Override
public String getFormattedValue(float value, AxisBase axis) {
    if (value >= list.size()) {
        value = list.size() - 1;
    }
    Date date = new Date(list.get((int) value) * 1000);
    return formatter.format(date);
}

Can someone come in handy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM