MPAndroidChart LineChart: Using dates instead of Strings for X-axis

微笑、不失礼 提交于 2019-12-01 17:19:39

问题


MPAndroidChart LineChart by default accepts Strings for X-axis. Is there a way to set Date as a datatype for the X-axis?

The problem with just converting Date into strings is that graph can be scewed depending on the data points. For example if I have one data entry on January and 10 entries in June, by default the graph is just split into 11 and plot accordingly.

I want a "You weight over time" graph, where X-Axis represents time. User weights in at random times, so some dates will have entry and some dates will not.


回答1:


I found a thread on the project's gitHub ( https://github.com/PhilJay/MPAndroidChart/issues/12 ).

Apparently, this feature is not yet implemented.

Update

Doing a bit of search, I found this alternative library:

https://github.com/lecho/hellocharts-android

It supports values for x-axis.




回答2:


You can make new array with full dates and fill empty positions with previous values. For example: you making an array may[31] for each day of may, initializate it with zeroes, and then do something like this:

may[1] = values[1];  
for (int i = 2; i <= may.size(); ++i) {
    if (may[i] == 0)
        may[i] = may[i-1];
    }


来源:https://stackoverflow.com/questions/32292466/mpandroidchart-linechart-using-dates-instead-of-strings-for-x-axis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!