我在AChartEngine中繪製兩個具有不同比例的Y軸(一個在右側和一個在左側)有問題:我想要將左側從0縮放到40這是正確的,但右側縮放不是渴望之一,因爲它應該從10到100.請幫助我。如何在AChartEngine中繪製兩個具有不同比例的Y軸
我的源代碼看起來象
公衆的LinearLayout執行(上下文的背景下){
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; }
完整的源代碼可以找到[這裏](HTTP:// naeemgik。 blogspot.com/2013/09/line-chart-using-achartengine-api-in.html) – sns