2013-05-14 52 views
1

我正在使用Achartengine庫創建默認條形圖。這些值不能正確顯示。我想在圖表頂部顯示圖表值,並與中心對齊。對我來說,只有第一欄的值是可見的,但我想看到兩欄的值。我怎樣才能做到這一點?我將不勝感激任何幫助。圖表值不顯示爲條形圖achartengine

這裏是我的代碼

public Intent getIntent(Context context) 
{ 
    // Bar 1 
    int[] y = { 124, 135, 443, 456, 234, 123, 342, 134, 123, 643, 234, 274 }; 
    CategorySeries series = new CategorySeries("Demo Bar Graph 1"); 
    for (int i = 0; i < y.length; i++) { 
     series.add("Bar " + (i+1), y[i]); 
    } 

    // Bar 2 
    int[] y2 = { 124, 135, 243, 256, 234, 223, 242, 234, 223, 243, 234, 274 }; 
    CategorySeries series2 = new CategorySeries("Demo Bar Graph 2"); 
    for (int i = 0; i < y.length; i++) { 
     series2.add("Bar " + (i+1), y2[i]); 
    } 

    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); 
    dataset.addSeries(series.toXYSeries()); 
    dataset.addSeries(series2.toXYSeries()); 

    // This is how the "Graph" itself will look like 
    XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(); 
    mRenderer.setChartTitle("Demo Graph Title"); 
    mRenderer.setXTitle("X VALUES"); 
    mRenderer.setYTitle("Y VALUES"); 
    mRenderer.setAxesColor(Color.GREEN); 
    mRenderer.setLabelsColor(Color.RED); 
    mRenderer.setBarSpacing(2.0f); 

    // Customize bar 1 
    XYSeriesRenderer renderer = new XYSeriesRenderer(); 
    renderer.setColor(Color.RED); 
    renderer.setDisplayChartValues(true); 
    renderer.setChartValuesSpacing((float) 2.5); 
    mRenderer.addSeriesRenderer(renderer); 

    // Customize bar 2 
    XYSeriesRenderer renderer2 = new XYSeriesRenderer(); 
    renderer.setColor(Color.GREEN); 
    renderer.setDisplayChartValues(true); 
    renderer.setChartValuesSpacing((float) 2.5); 
    mRenderer.addSeriesRenderer(renderer2); 

    Intent intent = ChartFactory.getBarChartIntent(context, dataset,mRenderer, Type.DEFAULT); 
    return intent; 
} 

回答

3

您實例化一個rendererrenderer2,但你打電話renderer.setDisplayChartValues(true)兩次,從不叫renderer2.setDisplayChartValue(true);

+0

+1你是對的。 – Raghunandan 2013-05-14 15:13:13

+0

謝謝,你是對的。你能告訴我如何對齊圖表值中心? – 2013-05-15 07:05:27

+0

renderer.setChartValuesTextAlign(); – 2013-05-15 07:14:14