4

我试图用 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" />

4

2 回答 2

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 View 显示的确切大小

于 2013-07-16T07:21:25.597 回答
0

尝试并删除

android:layout_gravity="center"
于 2014-10-14T07:13:40.480 回答