XML 파일을 파싱하고, 날짜와 값을 수집하고, 루프를 통과하는 for 루프와 데이터 포인트의 배열 목록을 사용하여이 데이터를 GraphView에 플롯하는 앱을 만들고 있습니다. 그래프에 날짜와 값의 범위가있는 x 축과 y 축을 생성 할 수는 있지만 포인트는 표시되지 않습니다.GraphView For 루프가 아닌 데이터
안드로이드 모니터에서 데이터 포인트가 생성되고 있음을 알 수 있습니다. 단지 플롯이되지 않습니다. 내 코드에 문제가있을 것입니다.하지만 알아낼 수는 없습니다. 어떤 아이디어?
업데이트 : XML 파일에 동일한 날짜에 대해 여러 값이 있다고 추가해야합니다 (데이터는 15 분마다 수집됩니다). 내 추측으로는 배열에서 이러한 값의 평균을 구해야하므로 날짜 당 하나의 값만 있습니다. 이것은 GraphView에 영향을 줄 수 있습니다.
공용 클래스 GraphActivity 내가 그것을 알아 냈 AppCompatActivity {
GraphView graphView;
LineGraphSeries<DataPoint> series;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_graph);
graphView = (GraphView) findViewById(R.id.graph);
try {
InputStream is = GraphActivity.this.getResources()
.getAssets().open("smallmonth.xml");
ArrayList<GraphDateEntry> dateOnlyEntrySeries = new GraphDateParsing2().parse(is);
InputStream is1 = GraphActivity.this.getResources()
.getAssets().open("smallmonth.xml");
ArrayList<GraphValueEntry> valueOnlySeries = new GraphValueParsing().parse(is1);
for (int i = 0; i < dateOnlyEntrySeries.size(); i++) {
Double value = Double.parseDouble(valueOnlySeries.get(i).value);
String stringDate = dateOnlyEntrySeries.get(i).date;
DataPoint dateAndValue = new DataPoint(new SimpleDateFormat("yyyy-MM-dd").parse(stringDate), value);
series = new LineGraphSeries<>();
series.appendData(dateAndValue, true, dateOnlyEntrySeries.size());
}
graphView.addSeries(series);
series.setColor(Color.BLACK);
series.setThickness(8);
graphView.getGridLabelRenderer().setLabelFormatter(new DefaultLabelFormatter() {
@Override
public String formatLabel(double value, boolean isValueX) {
if (isValueX) {
Log.d("formatLabel: ", sdf.format(new Date((long) value)));
return sdf.format(new Date((long) value));
} else {
return super.formatLabel(value, isValueX);
}
}
});
} catch (IOException ie) {
ie.printStackTrace();
} catch (ParseException pe) {
pe.printStackTrace();
}
}