2012-08-24 79 views
5

在Android上使用achartengine獲取多個Y軸以顯示在圖表上很難。我試圖複製在「Multiple Temperature Chart」演示中完成的操作:http://code.google.com/p/achartengine/source/browse/trunk/achartengine/demo/org/achartengine/chartdemo/demo/chart/MultipleTemperatureChart.java,但它不會在右側顯示Y軸,也不會顯示我想要顯示的Yaxis標籤。Android上的Achartengine - 多個Y軸

任何想法我的代碼可能是做錯了:

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

我使用的是時間序列圖,而不是cubicline圖表演示用途,但另有事情應該是差不多了。

回答

5

確保爲第二個系列分配了單獨的比例編號。例如,初始化mCurrentEffSeries這種方式,它會工作:

mCurrentEffSeries = new XYSeries(effTitle, 1); 
+1

太棒了!就是這樣。謝謝,丹。我喜歡achartengine,演示很好,但是它有點缺乏文檔。好東西StackOverflow在這裏 – Martin