有xml
:
<?xml version="1.0" encoding="utf-8"?>
<com.jjoe64.graphview.GraphView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dip"
android:id="@+id/graph">
</com.jjoe64.graphview.GraphView>
有java
:
LineGraphSeries<DataPoint> series;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_graph_weight);
GraphView graph = findViewById(R.id.graph);
for (int i = 0; i < FragmentDiaryWeight.weightDiaryList.size(); i++) {
series = new LineGraphSeries<>(new DataPoint[]{
new DataPoint(Integer.parseInt(FragmentDiaryWeight.weightDiaryList.get(i).getmDay()), Integer.parseInt(FragmentDiaryWeight.weightDiaryList.get(i).getmWeight())),
});
graph.addSeries(series);
}
}
我知道数据是从数组weightDiaryList
收集的,但是图中的线未显示。如果我将x和y替换为5和10,则一切正常。
如果我使用series.setDrawDataPoints(true)
,则指向正确显示。
如何解决?如何显示该图的线?
答案 0 :(得分:0)
GraphView graph = findViewById(R.id.graph);
for (int i = 0; i < FragmentDiaryWeight.weightDiaryList.size(); i++) {
series = new LineGraphSeries<>(new DataPoint[]{
new DataPoint(Integer.parseInt(FragmentDiaryWeight.weightDiaryList.get(i).getmDay()), Integer.parseInt(FragmentDiaryWeight.weightDiaryList.get(i).getmWeight())),
});
}
graph.addSeries(series);