JuiCe
JuiCe

Reputation: 4201

AChartEngine graph won't show up?

I have been using AChartEngine for a few weeks now, and as of last week everything was working fine. I really cannot find what I have changed, but now the graph just doesn't appear on my screen. My Activity initializes with an empty Layout attribute for the graph. At a certain point, the user reads in input and then the graph is updated.

Here is the XML code for my graph:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:background="@drawable/eti1"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:weightSum="11" >

    <LinearLayout
        android:id="@+id/wavesOptions"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:gravity="center"
        android:weightSum="8" >


        <!-- 

        Unrelated spinners/checkboxes

        -->
    <ScrollView
        android:layout_width="fill_parent"
        android:id="@+id/graphScroll"
        android:layout_height="wrap_content"
        android:layout_above="@id/wavesOptions"
        android:layout_alignParentTop="true" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <LinearLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/graph1"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </LinearLayout>

    </ScrollView>
</RelativeLayout>

Below is a picture of my layout as shown in Eclipse. The box outlined in blue at the top of my view is where my graph would be going. It looks small, but I use wrap_content for height, so it should match its parent. When I set the graph to that view in my java code, nothing cahnges at all. All of the checkboxes are updated and a new spinner is added correctly.

enter image description here

Below is my code from my .java file:

public void onCreate( Bundle savedInstanceState ) {
    super.onCreate( savedInstanceState );
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView( R.layout.waves );

    renderer = new XYMultipleSeriesRenderer( 2 ); 

}

Once the user calls for the information to graph, data is stored in an array called waveResults and the method updateGraph() is called. The important part where the graphView is set to the layout is all the way at the bottom:

public void updateGraph() {
    int num = 166;
    renderer = new XYMultipleSeriesRenderer( 2 );
    dataset = new XYMultipleSeriesDataset();

    // NetV1
    netV1Series = new XYSeries( "Net V1", 0 );
    // NetV2
    netV2Series = new XYSeries( "Net V2", 0 );
    // NetV3  
    netV3Series = new XYSeries( "Net V3", 0 );
    // VDI1
            // VDI2
            // VDI3
    if( spinnerChoice == 0 ) {
        vdi1Series = new XYSeries( "Diff V1", 1 );
        vdi2Series = new XYSeries( "Diff V2", 1 );
        vdi3Series = new XYSeries( "Diff V3", 1 );
    } else {
        vdi1Series = new XYSeries( "Curr 1", 1 );
        vdi2Series = new XYSeries( "Curr 2", 1 );
        vdi3Series = new XYSeries( "Curr 3", 1 );
    }

    dataset.addSeries( netV1Series );
    dataset.addSeries( netV2Series );
    dataset.addSeries( netV3Series );
    dataset.addSeries( vdi1Series );
    dataset.addSeries( vdi2Series );
    dataset.addSeries( vdi3Series );
    netV1Renderer = new XYSeriesRenderer();
    netV1Renderer.setColor( Color.WHITE );
    netV2Renderer = new XYSeriesRenderer();
    netV2Renderer.setColor( Color.YELLOW );
    netV3Renderer = new XYSeriesRenderer();
    netV3Renderer.setColor( Color.BLUE );
    vdi1Renderer = new XYSeriesRenderer();
    vdi1Renderer.setColor( Color.RED );
    vdi2Renderer = new XYSeriesRenderer();
    vdi2Renderer.setColor( Color.CYAN );
    vdi3Renderer = new XYSeriesRenderer();
    vdi3Renderer.setColor( Color.GRAY );
    renderer.addSeriesRenderer( netV1Renderer );
    renderer.addSeriesRenderer( netV2Renderer );
    renderer.addSeriesRenderer( netV3Renderer );
    renderer.addSeriesRenderer( vdi1Renderer );
    renderer.addSeriesRenderer( vdi2Renderer );
    renderer.addSeriesRenderer( vdi3Renderer );     

    renderer.setAxesColor( Color.DKGRAY );
    renderer.setPointSize( 14 );
    renderer.setApplyBackgroundColor( true );
    renderer.setBackgroundColor( Color.BLACK );
    renderer.setMarginsColor( Color.BLACK );
    renderer.setChartTitle( "Waves" );
    renderer.setShowGrid( true );
    renderer.setXLabels( 10 );
    renderer.setYLabels( 7 );
    renderer.setXLabelsAlign(Align.RIGHT);
    renderer.setYLabelsAlign(Align.RIGHT, 0);
    renderer.setZoomButtonsVisible( false );
    renderer.setPanEnabled( false, false );
    renderer.setZoomEnabled( false, false );
    renderer.setLabelsColor(Color.WHITE);
    renderer.setXLabelsColor(Color.WHITE);
    renderer.setYLabelsColor(0, Color.WHITE);
    renderer.setYLabelsColor(1, Color.WHITE);

    if( spinnerChoice == 0 ) {
        renderer.setYTitle("Diff Volts", 1);
    } else {
        renderer.setYTitle( "Current", 1 );
    }
    renderer.setYTitle( "Net Volts", 0 );

    renderer.setYAxisAlign( Align.LEFT, 0 );
    renderer.setYAxisAlign(Align.RIGHT, 1);
    renderer.setYLabelsAlign(Align.LEFT, 1);


    graphLayout = (LinearLayout) findViewById( R.id.graph1 );
    graphLayout.removeAllViews();
    Log.i( "GRAPH", "After Remove" );
    graphView = ChartFactory.getCubeLineChartView( getApplicationContext(), dataset, renderer, 0.3f);
    Log.i( "GRAPH",  "Before addView" );
    graphLayout.addView(graphView);
    Log.i( "GRAPH", "After addView" );
}

At the end of the updateGraph() method the three Log calls are all displayed in my LogCat.

Upvotes: 3

Views: 687

Answers (1)

Dan D.
Dan D.

Reputation: 32391

The problem is the ScrollView. I have only removed the ScrollView from your layout and the chart displayed fine.

Note the warning at the ScrollView in the waves.xml in edit mode: "This ScrollView layout or its LinearLayout parent is possibly useless".

Upvotes: 1

Related Questions