我在 AChartEngine 中以不同的缩放比例绘制两个 Y 轴(一个在右侧,一个在左侧)时遇到问题:我希望左侧从 0 缩放到 40,这是正确的,但右侧缩放不是想要的,因为它应该是从 10 到 100。请帮助我。
我的源代码看起来像这样
公共线性布局执行(上下文上下文){
String[] titles = new String[] { "Ciggars" };
List<double[]> x = new ArrayList<double[]>();
for (int i = 0; i < titles.length; i++) {
x.add(new double[] { 1, 2, 3, 4, 5, 6, 7});
}
List<double[]> values = new ArrayList<double[]>();
values.add(new double[] { 12.3, 12.5, 13.8, 16.8, 20.4, 24.4, 26.4, 26.1, 13.9 });
// Set color of lines
int[] colors = new int[] { Color.BLUE, Color.YELLOW };
PointStyle[] styles = new PointStyle[] { PointStyle.CIRCLE, PointStyle.DIAMOND};
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer(2);
setRenderer(renderer, colors, styles);
int length = renderer.getSeriesRendererCount();
for (int i = 0; i < length; i++) {
((XYSeriesRenderer) renderer.getSeriesRendererAt(i)).setFillPoints(true);
}
setChartSettings(renderer, "Average Cigarates", "Days", "Cigarates", 0, 7, 0, 40, Color.LTGRAY, Color.LTGRAY);
// fragments on X and Y-axis to be divided
renderer.setXLabels(7);
renderer.setYLabels(10);
renderer.setShowGrid(true);
renderer.setXLabelsAlign(Align.RIGHT);
renderer.setYLabelsAlign(Align.RIGHT);
renderer.setZoomButtonsVisible(true);
renderer.setZoomRate(1.05f);
renderer.setLabelsColor(Color.WHITE);
renderer.setXLabelsColor(Color.GREEN);
renderer.setYLabelsColor(0, colors[0]);
renderer.setYLabelsColor(1, colors[1]);
renderer.setYTitle("% Tar/Nicotine", 1);
//renderer.setYTitle(title, scale)
renderer.setYAxisAlign(Align.RIGHT, 1);
renderer.setYLabelsAlign(Align.LEFT, 1);
XYMultipleSeriesDataset dataset = buildDataset(titles, x, values);
values.clear();
values.add(new double[] { 4.3, 4.9, 5.9, 8.8, 10.8, 11.9, 13.6, 12.8});
addXYSeries(dataset, new String[] { "Tar/Nicotine" }, x, values, 1);
// set background color
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.GRAY);
renderer.setMarginsColor(Color.GRAY);
GraphicalView gview = ChartFactory.getCubeLineChartView(context, dataset, renderer, 0.3f);
LinearLayout lnr = null;
lnr = new LinearLayout(context);
lnr.addView(gview);
return lnr; }