2016-06-09 44 views
0
// 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); 

當使用一秒鐘作爲XAxis Graph不顯示時。但如果使用超過60秒,則顯示圖形。我不知道原因。任何人都有與GRaphView類似的問題。X軸中的時間 - GraphView for android

回答

0

使用最新版本的庫,並嘗試使用此:

graph.getGridLabelRenderer().setHumanRounding(false);