我有一张aChartEngine图表,其数值显示在图表上。问题是当我水平或垂直平移图表时,值会发生变化。看看这两个截图:
private GraphicalView initGraph(String chartTitle, String xTitle, String yTitle, String[] titles, List<double[]> x, List<double[]> values, int[] colors, PointStyle[] styles) {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(25);
renderer.setChartTitleTextSize(25);
renderer.setLabelsTextSize(20);
renderer.setLegendTextSize(20);
renderer.setPointSize(5f);
renderer.setTextTypeface(getDefaultTypeface());
renderer.setMargins(new int[] { 30, 60, 50, 10 }); // TOP,LEFT,BOTTOM,RIGHT
NumberFormat format = NumberFormat.getNumberInstance();
format.setMaximumFractionDigits(1);
int length = colors.length;
for (int i = 0; i < length; i++) {
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(colors[i]);
r.setPointStyle(styles[i]);
r.setFillPoints(true);
r.setChartValuesFormat(format);
renderer.addSeriesRenderer(r);
}
renderer.setChartTitle(chartTitle);
renderer.setXTitle(xTitle);
renderer.setYTitle(yTitle);
renderer.setAxesColor(Color.LTGRAY);
renderer.setLabelsColor(Color.LTGRAY);
//renderer.setXLabels(10);
//renderer.setYLabels(5);
//renderer.setShowGrid(true);
renderer.setXLabelsAlign(Align.CENTER);
renderer.setYLabelsAlign(Align.RIGHT);
renderer.setZoomButtonsVisible(true);
renderer.setDisplayChartValues(true);
renderer.setChartValuesTextSize(20);
renderer.setLabelFormat(format);
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
int titlesLength = titles.length;
for (int i = 0; i < titlesLength; i++) {
XYSeries series = new XYSeries(titles[i], 0);
double[] xV = x.get(i);
double[] yV = values.get(i);
int seriesLength = xV.length;
for (int k = 0; k < seriesLength; k++) {
series.add(xV[k], yV[k]);
}
dataset.addSeries(series);
}
return ChartFactory.getLineChartView(this, dataset, renderer);
}