AChartAngine条形图值不受缩放影响

时间:2016-06-15 09:50:13

标签: android charts vertical-alignment achartengine

我用aChartEngine生成一些条形图。一项活动内有9种不同的条形图。我的问题是,如果这些值很高,我就看不到图表值。

我尝试将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]);
}

1 个答案:

答案 0 :(得分:0)

更改每个multirender的yAxisMax解决了我的问题。

这一行:

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

已更改为

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