Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Achartengine on android - multiple Y axis

Having a hard time getting multiple Y axis to show up on a chart using achartengine on android. I have tried to copy what was done on the "Multiple Temperature Chart" demo here: http://code.google.com/p/achartengine/source/browse/trunk/achartengine/demo/org/achartengine/chartdemo/demo/chart/MultipleTemperatureChart.java but it won't show the Y axis on the right, nor will it show the Yaxis labels I want to show.

Any ideas what my code might be doing wrong:

    mCurrentCostSeries = new XYSeries(costTitle);
    mCurrentEffSeries = new XYSeries(effTitle);

    mDataset.addSeries(mCurrentCostSeries);
    mDataset.addSeries(mCurrentEffSeries);



    int[] colors = new int[] { Color.RED, Color.YELLOW };
    PointStyle[] styles = new PointStyle[] { PointStyle.POINT, PointStyle.DIAMOND };
    mRenderer = new XYMultipleSeriesRenderer(2);
    setRenderer(mRenderer, colors, styles);
    int length = mRenderer.getSeriesRendererCount();
    for (int i = 0; i < length; i++) {
      XYSeriesRenderer r = (XYSeriesRenderer) mRenderer.getSeriesRendererAt(i);
      r.setLineWidth(3f);
    }

    mRenderer.setApplyBackgroundColor(true);
    mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));

    mRenderer.setAxesColor(Color.LTGRAY);
    mRenderer.setZoomButtonsVisible(true);
    mRenderer.setPointSize(10);

    mRenderer.setChartTitle("Fuel Efficiency and Cost");


    mRenderer.setShowGrid(true);
    mRenderer.setXLabelsAlign(Align.RIGHT);
    mRenderer.setYLabelsAlign(Align.RIGHT);


    mRenderer.setYTitle(cunits,0);

    mRenderer.setLabelsColor(Color.WHITE);
    mRenderer.setXLabelsColor(Color.GREEN);
    mRenderer.setYLabelsColor(0, colors[0]);
    mRenderer.setYLabelsColor(1, colors[1]);



    mRenderer.setYTitle(dunits, 1);        // these lines SHOULD set the second Y axis 
    mRenderer.setYAxisAlign(Align.RIGHT, 1);// (series=1) but have no effect.
    mRenderer.setYLabelsAlign(Align.LEFT, 1);

I'm using a timeseries chart rather than a cubicline chart the demo uses but otherwise things ought to be almost the same.

like image 709
Martin Avatar asked Aug 24 '12 09:08

Martin


1 Answers

Make sure you allocate a separate scale number for the second series. For instance, initialize the mCurrentEffSeries this way and it will work:

mCurrentEffSeries = new XYSeries(effTitle, 1);
like image 173
Dan D. Avatar answered Oct 19 '22 19:10

Dan D.