[英]Time in axis X - GraphView for android
// generate Dates
Calendar calendar = Calendar.getInstance();
Date d1 = calendar.getTime();
calendar.add(Calendar.SECOND, 1);
Date d2 = calendar.getTime();
calendar.add(Calendar.SECOND, 1);
Date d3 = calendar.getTime();
GraphView graph = (GraphView) findViewById(R.id.graph);
// you can directly pass Date objects to DataPoint-Constructor
// this will convert the Date to double via Date#getTime()
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(new DataPoint[] {
new DataPoint(d1, 1),
new DataPoint(d2, 5),
new DataPoint(d3, 3)
});
graph.addSeries(series);
// set date label formatter
graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(getActivity()));
graph.getGridLabelRenderer().setNumHorizontalLabels(3); // only 4 because of the space
// set manual x bounds to have nice steps
graph.getViewport().setMinX(d1.getTime());
graph.getViewport().setMaxX(d3.getTime());
graph.getViewport().setXAxisBoundsManual(true);
当使用1秒作为XAxis时,不会显示图。 但是如果使用60秒以上,则会显示图形。 我不知道原因。 任何人对GRaphView都有类似的问题。
使用该库的最新版本,然后尝试使用此版本:
graph.getGridLabelRenderer().setHumanRounding(false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.