How to plot a graph with Time in x-axis and value on the other in android?

怎甘沉沦 提交于 2020-01-23 02:50:06

问题


I want to plot a Time vs value graph where time (in hours) is on the x-axis and the Values should be on the y-axis. Is there any library to do this? I tried using achartengine http://wptrafficanalyzer.in/blog/android-drawing-time-chart-with-timeseries-in-achartengine/ but not much helpful.


回答1:


you can use GraphView for doing this.

http://www.jjoe64.com/p/graphview-library.html

https://github.com/jjoe64/GraphView

you have to use a Custom label formatter. There's an example where the X-values are displayed as DateTime.

GraphView graphView = new LineGraphView(this, "example") {
   @Override
   protected String formatLabel(double value, boolean isValueX) {
      if (isValueX) {
         // convert unix time to human time
         return dateTimeFormatter.format(new Date((long) value*1000));
      } else return super.formatLabel(value, isValueX); // let the y-value be normal-formatted
   }
};

It should be easy to modify this to your purpose.



来源:https://stackoverflow.com/questions/16850789/how-to-plot-a-graph-with-time-in-x-axis-and-value-on-the-other-in-android

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