2013-04-03 33 views
4

我试图绘制一些图表与AFreeChart和它的工作非常好。 但是图表没有填满显示屏上的所有可用空间。我怎样才能做到这一点?AFreeChart图表不填充母

<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" /> 

回答

2

如果您正在使用AbsChartView作为基地,图表视图, 去paintComponent并将其更改为这个代码段:

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; 
} 

它将使用的确切大小的机器人查看显示的是

0

尝试并删除

android:layout_gravity="center" 
+1

@arulmr这也* *提供答案。它可以做更多的解释,因此可能需要反对票。 –

+0

虽然这个代码块可能会回答这个问题,但最好能提供一些解释。 – DavidPostill