Achartengine on android - multiple Y axis

帅比萌擦擦* 提交于 2020-01-02 05:06:06

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/12106645/achartengine-on-android-multiple-y-axis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!