JJOE64 Android graphview动态设置LineGraphSeries

mes*_*mia 4 android android-graphview

嗨,我正在尝试使用此库绘制图表,但其条目静态如下:

LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(new DataPoint[] {

                        new DataPoint(0, 1),
                        new DataPoint(1, 5),
                        new DataPoint(2, 3),
                        new DataPoint(3, 2),
                        new DataPoint(4, 6)
                });
                graph.addSeries(series);
Run Code Online (Sandbox Code Playgroud)

我如何解决这个接受前的问题.在运行时创建的列表视图元素?基本上我想要这样的东西:

for (int i = 0; i < list.size(); i++) {
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(new DataPoint[] {

                        new DataPoint(i, list.getElement()),
});
}
Run Code Online (Sandbox Code Playgroud)

Slo*_*vić 7

尝试这样的事情:

DataPoint[] dataPoints = new DataPoint[list.size()]; // declare an array of DataPoint objects with the same size as your list
for (int i = 0; i < list.size(); i++) {
    // add new DataPoint object to the array for each of your list entries
    dataPoints[i] = new DataPoint(i, list.getElement()); // not sure but I think the second argument should be of type double
}

LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(dataPoints); // This one should be obvious right? :)
Run Code Online (Sandbox Code Playgroud)