user2970105
user2970105

Reputation:

ScrollView not working with aChartEngine

I am trying to put multiple charts on a single activity, and use a scrollview to view them all.

The first two charts are showing up but the second two are not. I have followed all the instructions from the tutorials, and have followed all the suggestions on stack, but none of them work.

I have also tried removing the scrollview, but the charts are still not displaying. Any help would be greatly appreciated.

XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >



    <ScrollView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fillViewport="true"
>

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


    <LinearLayout
    android:id="@+id/chart"
    android:layout_width="fill_parent"
    android:layout_height="300dp" 
    android:orientation="horizontal" />

    <LinearLayout
    android:id="@+id/chart1"
    android:layout_width="fill_parent"
    android:layout_height="300dp"
    android:layout_below="@id/chart"
    android:orientation="horizontal" />

     <LinearLayout
    android:id="@+id/chart2"
    android:layout_width="fill_parent"
    android:layout_height="300dp"
    android:layout_below="@id/chart1"
    android:orientation="horizontal" />

      <LinearLayout
    android:id="@+id/chart3"
    android:layout_width="fill_parent"
    android:layout_height="300dp"
    android:layout_below="@id/chart2"
    android:orientation="horizontal" />

     </LinearLayout>

     </ScrollView>

</RelativeLayout>

Linegraph.java

public class LineGraph extends Activity{

    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();    
    protected static GraphicalView mChartView;

    public GraphicalView getView(Context context, int[]z, int []zz){

        CategorySeries series = new CategorySeries("line1");


    for(int i=0;i<z.length;i++){
        series.add("Bar " + (i+1),z[i]);
    }


    CategorySeries series2= new CategorySeries("demo");
    for(int i=0;i<zz.length;i++){
        series2.add("Bar " + (i+1),zz[i]);
    }

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

    XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
    mRenderer.setAxesColor(Color.GREEN);

    XYSeriesRenderer renderer = new XYSeriesRenderer();
    renderer.setDisplayChartValues(true);
    renderer.setChartValuesSpacing((float)0.5);
    mRenderer.addSeriesRenderer(renderer);

    mRenderer.setZoomEnabled(false);
    mRenderer.setPanEnabled(false);
    mRenderer.setZoomRate(6.0f);
    mRenderer.setShowLabels(true);
    mRenderer.setFitLegend(true);
    mRenderer.setInScroll(true); 


    XYSeriesRenderer renderer2 = new XYSeriesRenderer();
    renderer.setColor(Color.CYAN);
    renderer.setDisplayChartValues(true);
    mRenderer.addSeriesRenderer(renderer2);




        return ChartFactory.getLineChartView(context, dataset, mRenderer);



    }




}

MainActivity:

public class MainActivity extends LineGraph {

    int a[] ={1,2,3};
    int b[] ={4,5,6};
    int c[] ={7,8,9};
    int d[] ={10,11,12};
    int e[] ={13,14,15};
    int f[] ={16,17,18};
    int g[] ={19,20,21};
    int h[] ={22,23,24};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main); 
        lineGraphHandler ();

    }




    public void lineGraphHandler (){
        LineGraph line = new LineGraph();
        GraphicalView gView = line.getView(this, a,b);
        GraphicalView gV = line.getView(this,c,d);
        GraphicalView gV2 = line.getView(this,e,f);
        GraphicalView gV3 = line.getView(this,g,h);

        LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
        layout.addView(gView);      

        LinearLayout layout2 = (LinearLayout) findViewById(R.id.chart1);
        layout2.addView(gV);

        LinearLayout layout3 = (LinearLayout) findViewById(R.id.chart2);
        layout2.addView(gV2);

        LinearLayout layout4 = (LinearLayout) findViewById(R.id.chart3);
        layout2.addView(gV3);
    }



}

Upvotes: 0

Views: 471

Answers (2)

KOTIOS
KOTIOS

Reputation: 11194

You cannot scroll inside ScrollView :

As i can see above u use

 <ScrollView>
 </ScrollView> 

And inside it embedded layouts which will contain chart which you need scrollable, unfortunately nested scroll doesn't seems to work.

Upvotes: 0

TaRan LaYal
TaRan LaYal

Reputation: 148

Use Scroll view as your parent layout rather than the Relative layout

Upvotes: 1

Related Questions