这里我试图在x轴上显示一个带有日期的图表,其中从Web服务器检索值:
// Our first data
Date[] x = dates_array; // x values!
double[] y = readings_array; // y values!
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(); // Holds a collection of XYSeriesRenderer and customizes the graph
XYSeriesRenderer renderer = new XYSeriesRenderer(); // This will be used to customize line 1
XYSeriesRenderer renderer2 = new XYSeriesRenderer(); // This will be used to customize line 2
mRenderer.addSeriesRenderer(renderer);
mRenderer.addSeriesRenderer(renderer2);
TimeSeries series = new TimeSeries("peak flow");
for( int i = 0; i < x.length; i++)
{
series.add(x[i], y[i]);
}
// Our second data
int[] x2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // x values!
int[] y2 = { 145, 123, 111, 100, 89, 77, 57, 45, 34, 30}; // y values!
TimeSeries series2 = new TimeSeries("Line2");
for( int i = 0; i < x2.length; i++)
{
series2.add(x2[i], y2[i]);
}
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(series);
dataset.addSeries(series2);
// Customization time for line 1!
renderer.setColor(Color.WHITE);
renderer.setPointStyle(PointStyle.SQUARE);
renderer.setFillPoints(true);
// Customization time for line 2!
renderer2.setColor(Color.YELLOW);
renderer2.setPointStyle(PointStyle.DIAMOND);
renderer2.setFillPoints(true);
Intent intent = ChartFactory.getTimeChartIntent(getApplicationContext(), dataset,
mRenderer, "DD MMM yyyy");
startActivity(intent);
}
});
它与y轴工作正常但在x轴上显示的值是随机值而不是我的值! 有什么帮助吗?
答案 0 :(得分:1)
在TimeSeries
中,您应该使用add(Date x, double y)
方法,而不是add(double x, double y)
方法。
如果您希望X轴标签完全符合数据的日期,请执行以下操作:
renderer.setXRoundedLabels(false);