График Оксиплота занимает весь экран для отображения

Я только начал использовать библиотеку 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;
    }

Вот моя собственность заговора:

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

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

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"/>
Другие вопросы по тегам