4

I tried to plot some graphs with AFreeChart and It's working pretty well. But chart not filling all available space at the display. How can I achieve this?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_gravity="center" >

<com.example.digitalfilter.DemoView
    android:id="@+id/demoView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

user1685095
  • 5,787
  • 9
  • 51
  • 100

2 Answers2

2

If you are using AbsChartView as your base chart view, go to paintComponent and change it to this code section:

    public void paintComponent(Canvas canvas) {

    // first determine the size of the chart rendering area...
    Dimension size = getSize();
    RectangleInsets insets = getInsets();
    RectShape available = new RectShape(insets.getLeft(), insets.getTop(),
            size.getWidth() - insets.getLeft() - insets.getRight(),
            size.getHeight() - insets.getTop() - insets.getBottom());

    double drawWidth = available.getWidth();
    double drawHeight = available.getHeight();
    this.scaleX = 1.0;
    this.scaleY = 1.0;

    RectShape chartArea = new RectShape(0.0, 0.0, drawWidth,
            drawHeight);

    this.chart.draw(canvas, chartArea, this.anchor, this.info);

    this.anchor = null;
}

It will then use the exact size the android View is displaying

Sean
  • 5,176
  • 2
  • 34
  • 50
0

Try and remove

android:layout_gravity="center"
arulmr
  • 8,620
  • 9
  • 54
  • 69
Bee
  • 1
  • 2
  • 1
    @arulmr This *does* provide an answer. It could do with some more explanation, so perhaps a down-vote is required. – Duncan Jones Oct 14 '14 at 07:51
  • While this code block may answer the question, it would be best if you could provide some explanation for why it does so. – DavidPostill Jan 10 '15 at 12:18