【问题标题】:How to plot a graph with Time in x-axis and value on the other in android?如何在 android 中绘制一个 x 轴上的时间和另一个值的图形?
【发布时间】:2013-05-31 06:12:09
【问题描述】:

我想绘制 时间 图,其中时间(以小时为单位)位于 x 轴上,值应位于 y 轴上。有没有图书馆可以做到这一点?我尝试使用 achartengine http://wptrafficanalyzer.in/blog/android-drawing-time-chart-with-timeseries-in-achartengine/ 但没有多大帮助。

【问题讨论】:

    标签: java android graph android-graphview


    【解决方案1】:

    您可以使用 GraphView 来执行此操作。

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

    https://github.com/jjoe64/GraphView

    您必须使用Custom label formatter。有一个示例,其中 X 值显示为 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
       }
    };
    

    应该很容易根据您的目的进行修改。

    【讨论】:

    • 查看在时间轴上绘制的数据时,您希望 x 轴标签具有漂亮的圆形值:整小时、30 分钟等。这对于您的任意标签解决方案是不可能的。
    • 在哪里可以找到LineGraphView
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-24
    相关资源
    最近更新 更多