我正在尝试使用此引擎构建折线图。它绘制得像我预期的那样,除了没有显示我的值。我看不出我的错误在哪里,请帮帮我。这是代码:
private View getLineChart(Context context)
{
List<Double> weights = App.helper.getWeights();
List<String> weightsDate = App.helper.getWeightsDate();
for(int x = 0; x < weights.size(); x++)
{
for(int y = x + 1; x < weights.size(); x++)
{
if(weights.get(x) > weights.get(y))
{
double temp = weights.get(x);
weights.set(x, weights.get(y));
weights.set(y, temp);
}
}
}
List<Date> dateList = new ArrayList<Date>();
for(int x = 0; x < weightsDate.size(); x++)
{
Date date = new Date(weightsDate.get(x));
dateList.add(date);
}
Collections.sort(dateList);
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
XYSeriesRenderer xyRenderer = new XYSeriesRenderer();
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
renderer.addSeriesRenderer(xyRenderer);
renderer.setChartTitle("Histórico de Peso");
renderer.setYTitle("Peso");
renderer.setYLabels(weights.size());
renderer.setYAxisMin(weights.get(0));
renderer.setYAxisMax(weights.get(weights.size() - 1));
renderer.setYAxisAlign(Align.LEFT, 0);
renderer.setYLabelsAlign(Align.LEFT, 0);
renderer.setXTitle("Data");
renderer.setXLabels(weights.size());
renderer.setXAxisMin(dateList.get(0).getTime(), 0);
renderer.setXAxisMax(dateList.get(dateList.size() - 1).getTime(), 0);
renderer.setXLabelsAlign(Align.CENTER);
renderer.setAxisTitleTextSize(12);
renderer.setChartTitleTextSize(12);
renderer.setLabelsTextSize(10);
renderer.setLegendTextSize(12);
renderer.setPointSize(5f);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.parseColor("#F5F5F5"));
renderer.setMarginsColor(Color.parseColor("#F5F5F5"));
renderer.setAxesColor(Color.LTGRAY);
renderer.setLabelsColor(Color.parseColor("#5f5f5f"));
renderer.setShowGrid(true);
renderer.setGridColor(Color.GRAY);
XYSeries series = new XYSeries("Peso");
for(int x = 0; x < weights.size(); x++)
{
series.add(weights.get(x), dateList.get(x).getTime());
}
dataset.addSeries(series);
View view = ChartFactory.getLineChartView(context, dataset, renderer);
Log.d("WEIGHT_TEST", String.valueOf(weights.get(0)));
return view;
}
我在onResume方法上调用它。绘制图表,但不考虑最小值和最大值,并且也不遵守标签计数。另外,有没有办法在X轴上显示dd / MM / yyyy日期?