【问题标题】:Oxyplot graph takes up whole screen for displayOxyplot 图形占据整个屏幕显示
【发布时间】:2018-12-11 19:59:56
【问题描述】:

我刚开始在我的项目中使用 oxyplot 库。我在我的项目中成功添加了一个圆环图,但问题是它占据了整个屏幕来显示图表。尝试了很多方法来解决这个问题,但都没有奏效。

这是我的 axml:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    local:layout_behavior="@string/appbar_scrolling_view_behavior" >
    <OxyPlot.Xamarin.Android.PlotView
        android:id="@+id/plot_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        local:MvxBind="Model DonutChart"/>
    <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="16dp"
            local:MvxBind="Text TestText1" />
    <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="16dp"
            local:MvxBind="Text TestText2" />
    <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="16dp"
            local:MvxBind="Text TestText3" />
</LinearLayout>

这是图形方法:

private void GeneratePlotModel()
    {
        var plotmodel = new PlotModel();

        var seriesP1 = new PieSeries
        {
            Stroke = OxyColors.Transparent,
            StrokeThickness = 2.0,
            InsideLabelPosition = 0.0,
            AngleSpan = 360,
            StartAngle = 0,
            InnerDiameter = 0.7,
            OutsideLabelFormat = null,
            InsideLabelFormat = null,
            TickHorizontalLength = 0.0,
            TickRadialLength = 0.0
        };

        seriesP1.Slices.Add(new PieSlice("Test 1", test1) { IsExploded = false, Fill = OxyColors.Blue });
        seriesP1.Slices.Add(new PieSlice("Test 2", test2) { IsExploded = false, Fill = OxyColors.Green });
        seriesP1.Slices.Add(new PieSlice("Test 3", test3) { IsExploded = false, Fill = OxyColors.Red });

        plotmodel.Series.Add(seriesP1);

        DonutChart = plotmodel;
    }

这是我的 plotmodel 属性:

private PlotModel _donutChart ;
    public PlotModel DonutChart 
    {
        get => _donutChart ;
        set
        {
            if (_donutChart == value)
                return;

            _donutChart = value;
            RaisePropertyChanged(nameof(DonutChart ));
        }
    }

【问题讨论】:

    标签: xamarin.android mvvmcross oxyplot


    【解决方案1】:

    因为你设置了,所以显示图形会占据整个屏幕

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    

    您可以通过添加使其仅占用空间

    android:layout_weight="1"

    所以布局是这样的:

    <OxyPlot.Xamarin.Android.PlotView
            android:id="@+id/plot_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            local:MvxBind="Model DonutChart"/>
    

    【讨论】:

    • 是的,我确实将 layout_weightlayout_height 设置为 0dp 并且它有效。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-11
    • 2019-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多