2013-04-03 32 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