2016-06-15 34 views
0

我用aChartEngine生成一些條形圖。一個活動內有9個不同的barcharts。我的問題是,如果這些值很高,我看不到圖表值。AChartAngine條形圖數值縮小

我試圖將layout_height參數更改爲fill_parent或wrap_content。但是,整個圖表是不可見的。所以我必須使用layout_height的固定值。

但是,如何更改圖表以查看所有圖表值?

我會附上兩張照片。一個小值的條形圖和一個不顯示的大值條形圖之一。

圖片1:Small values all looks good, 圖片2:One big Value, Chart value is not displayed

我的佈局是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
android:id="@+id/barchart_diagram_scrollview_parent" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
xmlns:android="http://schemas.android.com/apk/res/android"> 
<ScrollView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <LinearLayout android:id="@+id/barchart_diagram_parent" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 
     <LinearLayout 
      android:id="@+id/chart_container_szenario1" 
      android:orientation="horizontal" 
      android:layout_width="wrap_content" 
      android:layout_height="380dp"> 
     </LinearLayout> 
     <LinearLayout 
      android:id="@+id/chart_container_szenario2" 
      android:orientation="horizontal" 
      android:layout_width="wrap_content" 
      android:layout_height="350dp"> 
     </LinearLayout> 
     <LinearLayout 
      android:id="@+id/chart_container_szenario3" 
      android:orientation="horizontal" 
      android:layout_width="wrap_content" 
      android:layout_height="350dp"> 
     </LinearLayout> 
     <LinearLayout 
      android:id="@+id/chart_container_szenario4" 
      android:orientation="horizontal" 
      android:layout_width="wrap_content" 
      android:layout_height="350dp"> 
     </LinearLayout> 
     <LinearLayout 
      android:id="@+id/chart_container_szenario5" 
      android:orientation="horizontal" 
      android:layout_width="wrap_content" 
      android:layout_height="350dp"> 
     </LinearLayout> 
     <LinearLayout 
      android:id="@+id/chart_container_szenario6" 
      android:orientation="horizontal" 
      android:layout_width="wrap_content" 
      android:layout_height="350dp"> 
     </LinearLayout> 
     <LinearLayout 
      android:id="@+id/chart_container_szenario7" 
      android:orientation="horizontal" 
      android:layout_width="wrap_content" 
      android:layout_height="350dp"> 
     </LinearLayout> 
     <LinearLayout 
      android:id="@+id/chart_container_szenario8" 
      android:orientation="horizontal" 
      android:layout_width="wrap_content" 
      android:layout_height="350dp"> 
     </LinearLayout> 
     <LinearLayout 
      android:id="@+id/chart_container_szenario9" 
      android:orientation="horizontal" 
      android:layout_width="wrap_content" 
      android:layout_height="350dp"> 
     </LinearLayout> 
    </LinearLayout> 
</ScrollView> 
</LinearLayout> 

,這是我的代碼用於生成圖表:

dataset[szenario-1] = new XYMultipleSeriesDataset(); 
    multiRenderer[szenario-1] = new XYMultipleSeriesRenderer(); 

    couchseries[szenario-1] = new XYSeries("CouchBase"); 
    couchseries[szenario-1].add(1, szenarioXSizes[0]); 
    perstseries[szenario-1] = new XYSeries("PerstDB"); 
    perstseries[szenario-1].add(2, szenarioXSizes[1]); 
    sqliteseries[szenario-1] = new XYSeries("SQLite"); 
    sqliteseries[szenario-1].add(3, szenarioXSizes[2]); 


    //Formatierung 
    couchRenderer[szenario-1] = new XYSeriesRenderer(); 
    couchRenderer[szenario-1].setColor(Color.RED); 
    couchRenderer[szenario-1].setDisplayChartValues(true); 
    couchRenderer[szenario-1].setChartValuesTextSize(40); 

    perstRenderer[szenario-1] = new XYSeriesRenderer(); 
    perstRenderer[szenario-1].setColor(Color.GREEN); 
    perstRenderer[szenario-1].setDisplayChartValues(true); 
    perstRenderer[szenario-1].setChartValuesTextSize(40); 


    sqliteRenderer[szenario-1] = new XYSeriesRenderer(); 
    sqliteRenderer[szenario-1].setColor(Color.BLUE); 
    sqliteRenderer[szenario-1].setDisplayChartValues(true); 
    sqliteRenderer[szenario-1].setChartValuesTextSize(40); 

    //Min Max X Werte ermitteln 
    min[szenario-1] = 0; 
    max[szenario-1] = 0; 
    for(int i = 0; i < szenarioXSizes.length; i++) { 
     if(szenarioXSizes[i] < min[szenario-1]) 
      min[szenario-1] = szenarioXSizes[i]; 
     if(szenarioXSizes[i] > max[szenario-1]) 
      max[szenario-1] = szenarioXSizes[i]; 
    } 
    MainActivity.log("Gerding", "min: " + min[szenario-1] + " max: " + max[szenario-1]); 

    //Achsen 
    multiRenderer[szenario-1].addSeriesRenderer(couchRenderer[szenario-1]); 
    multiRenderer[szenario-1].addSeriesRenderer(perstRenderer[szenario-1]); 
    multiRenderer[szenario-1].addSeriesRenderer(sqliteRenderer[szenario-1]); 
    multiRenderer[szenario-1].setYAxisMin(0.0); 
    multiRenderer[szenario-1].setYAxisMax(max[szenario-1] + 100); 
    multiRenderer[szenario-1].setXAxisMin(0); 
    multiRenderer[szenario-1].setXAxisMax(4); 
    multiRenderer[szenario-1].setLabelsTextSize(20); 
    multiRenderer[szenario-1].setLegendTextSize(30); 
    multiRenderer[szenario-1].setZoomRate(2); 
    multiRenderer[szenario-1].setXTitle("Datenbank"); 
    multiRenderer[szenario-1].setYTitle("Speicherplatz in Bytes"); 
    multiRenderer[szenario-1].setAxisTitleTextSize(30); 
    multiRenderer[szenario-1].setChartTitle("Szenario " + szenario); 
    multiRenderer[szenario-1].setChartTitleTextSize(40); 
    multiRenderer[szenario-1].setPanEnabled(false,false); 
    multiRenderer[szenario-1].setZoomEnabled(false, false); 

    //Sets the margins, in pixels. order: top, left, bottom, right 
    multiRenderer[szenario-1].setMargins(new int[]{80, 80, 65, 80}); 

    //Farbgebung 
    multiRenderer[szenario-1].setApplyBackgroundColor(true); 
    multiRenderer[szenario-1].setBackgroundColor(Color.WHITE); 
    multiRenderer[szenario-1].setMarginsColor(Color.WHITE); 
    multiRenderer[szenario-1].setLabelsColor(Color.BLACK); 
    multiRenderer[szenario-1].setGridColor(Color.BLACK); 
    multiRenderer[szenario-1].setXLabelsColor(Color.BLACK); 
    multiRenderer[szenario-1].setYLabelsColor(0,Color.BLACK); 
    multiRenderer[szenario-1].setXAxisColor(Color.BLACK); 
    multiRenderer[szenario-1].setYAxisColor(Color.BLACK); 
    multiRenderer[szenario-1].clearXTextLabels(); 
    multiRenderer[szenario-1].setXLabels(0); 

    dataset[szenario-1].addSeries(couchseries[szenario-1]); 
    dataset[szenario-1].addSeries(perstseries[szenario-1]); 
    dataset[szenario-1].addSeries(sqliteseries[szenario-1]); 

    chartContainer[szenario-1] = (LinearLayout) findViewById(chartContainerID[szenario-1]); 
    types[szenario-1] = new CombinedXYChart.XYCombinedChartDef[] 
      { 
        new CombinedXYChart.XYCombinedChartDef(BarChart.TYPE, 0), 
        new CombinedXYChart.XYCombinedChartDef(BarChart.TYPE, 1), 
        new CombinedXYChart.XYCombinedChartDef(BarChart.TYPE, 2) 
      }; 
    mChart[szenario-1] = (GraphicalView) ChartFactory.getCombinedXYChartView(getBaseContext(), dataset[szenario-1], multiRenderer[szenario-1], types[szenario-1]); 
    mChart[szenario-1].setBackgroundColor(Color.WHITE); 
    // Adding the Combined Chart to the LinearLayout 
    chartContainer[szenario-1].addView(mChart[szenario-1]); 
} 

回答

0

更改每個multirenderder的yAxisMax修復了我的問題。

這一行:

multiRenderer[szenario-1].setYAxisMax(max[szenario-1] + 100);  

改爲

multiRenderer[szenario-1].setYAxisMax(max[szenario-1] + (max[szenario-1]/6));