Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用日期和小数作为轴的Android Graphview_Java_Android_Android Graphview - Fatal编程技术网

Java 使用日期和小数作为轴的Android Graphview

Java 使用日期和小数作为轴的Android Graphview,java,android,android-graphview,Java,Android,Android Graphview,基本上我需要使用Graphview Api() 根据我的高分绘制一些数据 到目前为止,我可以创建一个包含硬编码数据的折线图,如下所示: GraphView graph = (GraphView) findViewById(R.id.graph); LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(new DataPoint[] { // da

基本上我需要使用Graphview Api() 根据我的高分绘制一些数据

到目前为止,我可以创建一个包含硬编码数据的折线图,如下所示:

        GraphView graph = (GraphView) findViewById(R.id.graph);
    LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(new DataPoint[] {
            // date then score
            new DataPoint(0, 1),
            new DataPoint(1, 5),
            new DataPoint(2, 3),
            new DataPoint(3, 2),
            new DataPoint(2, 2)
    });
    graph.addSeries(series);
GraphView graph=(GraphView)findViewById(R.id.graph);
LineGraphSeries=新的LineGraphSeries(新数据点[]){
//日期然后得分
新数据点(0,1),
新数据点(1,5),
新数据点(2,3),
新数据点(3,2),
新数据点(2,2)
});
图.addSeries(系列);
但是,我的数据存储在2个ArrayList中

    final ArrayList<Date>date = new ArrayList<Date>();
    final ArrayList<BigDecimal> score= new ArrayList<BigDecimal>();
final ArrayListdate=new ArrayList();
最终ArrayList分数=新ArrayList();
我想用日期作为横轴,分数作为纵轴来绘制图表

我以前从未使用过graphview,我正在努力掌握如何有效地使用它

任何帮助都会很好
谢谢

这是我项目中的一个例子

barGraph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(context));
当然,您必须首先转换数据源,如下所示:

        DataPoint[] volumeDataPoints = new DataPoint[graphDots.size()];
        int i = 0 ;
        for(MainGraphDot gd :  graphDots){
            volumeDataPoints[i] = new DataPoint(gd.getDate(),gd.getV());
            i++;
        }
DataPoint是graphView可接受的阵列类型。可以直接将日期对象设置为X值,BigDecimal值是Y值

注意:DateAsXAxisLabelFormatter还可以获取DateFormat作为其构造函数的第二个参数,以便您可以更改日期值的格式