AChartEngine graph not showing up?

I have been using AChartEngine for several weeks and everything worked fine last week. I really can't find what I changed, but now the graph just doesn't appear on my screen. Mine Activity

initializes with an attribute an empty layout for the graph. At some point, the user reads the 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 an image of my layout as shown in Eclipse. The box outlined in blue at the top of my view is my graph. It looks small, but I am using wrap_content

for the height, so it should match its parent. When I set the graph for this view in my java code, nothing happens at all. All checkboxes have been updated and the new counter has been 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 ); 

}

      

As soon as the user calls information on the chart, the data is stored in an array named waveResults

and the method is called updateGraph()

. The important part where the graphical representation is set to the layout is 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 method, updateGraph()

three calls Log

show up in my LogCat.

+3


source to share


1 answer


The problem is ScrollView

. I just removed ScrollView

from your layout and the chart displayed fine.



Note the warning in ScrollView

wave.xml in edit mode: "This ScrollView or its parent LinearLayout is probably not useful."

+1


source







All Articles