AFreeChart图表未填写父母

时间:2013-04-03 17:31:24

标签: java android jfreechart

我尝试使用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 个答案:

答案 0 :(得分: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;
}

然后它将使用android视图显示的确切大小

答案 1 :(得分:0)

尝试删除

android:layout_gravity="center"