我在AChartEngine中绘制两个不同比例的Y轴(一个在右边,一个在左边)时遇到问题:我希望左侧从0到40缩放,这是正确的,但是右侧缩放不是渴望一个,因为它应该是从10到100.请帮助我。
我的源代码看起来像这样
public LinearLayout execute(Context context){
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; }
答案 0 :(得分:4)
您正在为右侧具有Y轴的系列添加这些值:
values.add(new double[] { 4.3, 4.9, 5.9, 8.8, 10.8, 11.9, 13.6, 12.8 });
由于AChartEngine默认计算可见范围,因此Y轴的范围介于4.3和13.6之间。
因此,您必须将值设置在10到100之间,或者您必须以这种方式手动修改可见范围:
renderer.setYAxisMin(10, 1);
renderer.setYAxisMax(100, 1);