Question

i'm very new to Android and AChartengine and i'm working in my project.

Assume i have a Layout like this:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity" >

<LinearLayout
     android:id="@+id/displayECG"
     android:layout_width="fill_parent"
     android:layout_height="100px"
    android:orientation="horizontal" >

</LinearLayout>

And in MainActivity.java i code like:

view = ChartFactory.getLineChartView(this, dataSet, renderer);
LinearLayout layout = (LinearLayout) findViewById(R.id.displayECG);
layout.addView(view, new LayoutParams(LayoutParams.MATCH_PARENT,    LayoutParams.MATCH_PARENT));

But when i run my App and i got a graph, it very smaller than layout space. I want a graph, it fits with my layout, so how can i do that?

Thanks,

Was it helpful?

Solution

Your chart is actually filling up the whole layout, but by default AChartEngine has a lot of extras turned on. I would suggest adding the following lines prior to creating the chart:

renderer.setLegendHeight(1);
renderer.setZoomButtonsVisible(false);
renderer.setMargins(new int[] {0, 0, 0, 0});

There may be a couple other things you need, but this should at least get you started. Also, your displayECG is only 100 px tall. That may be limiting as well.

OTHER TIPS

I am not familiar with the ChartFactory.

But from the layout perspective your giving a hight of 100px to the nested LinearLayout, try using wrap_content instead.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical"
   tools:context=".MainActivity" >

   <LinearLayout
      android:id="@+id/displayECG"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal" >

   </LinearLayout>

Also, try calling invalidate on the layout after you add the child view for it to redraw itself:

view = ChartFactory.getLineChartView(this, dataSet, renderer);
LinearLayout layout = (LinearLayout) findViewById(R.id.displayECG);
layout.addView(view, new LayoutParams(LayoutParams.MATCH_PARENT,   LayoutParams.MATCH_PARENT));
layout.invalidate();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top