locked
How to use a OxyPlot Bar Chart inside a listview control for Xamarin.Forms IOS? RRS feed

  • Question

  • User88449 posted

    I have a ListView with a binding template. And I have a list of PlotModels which I am using to bind to the list view. And my PlotView is inside the template where I am binding the PlotModel to the PlotView.

    Everything is running smooth in Android. But the problem is I am getting a error "PlotModel is already in use by some other PlotView control.". when I am trying to run it on IOS.

    Any suggestions?

    Thursday, May 25, 2017 5:01 AM

All replies

  • User263383 posted

    https://github.com/oxyplot/oxyplot-xamarin/issues/60

    Sunday, June 11, 2017 5:39 AM
  • User248173 posted

    @RishmitaSolipuram

    i think it will help you

    In Page Constructor:

            PlotModel model1 = new PlotModel();
            PieSeries ps1 = new PieSeries
            {
                Diameter = 1,
                InnerDiameter = 0.8,
                StrokeThickness = 0,
                AngleSpan = 360,
                StartAngle = 0,
                InsideLabelFormat = null,
                OutsideLabelFormat = null,
            };
            ps1.Slices.Add(new PieSlice("", 20) { Fill = Color.Red.ToOxyColor() });
            ps1.Slices.Add(new PieSlice("", 25) { Fill = Color.Blue.ToOxyColor() });
            ps1.Slices.Add(new PieSlice("", 20));
            ps1.Slices.Add(new PieSlice("", 10) { Fill = Color.DarkOrange.ToOxyColor() });
            ps1.Slices.Add(new PieSlice("", 25) { Fill = Color.Accent.ToOxyColor() });
            model1.Series.Add(ps1);
    
            PlotModel model2 = new PlotModel();
            PieSeries ps2 = new PieSeries
            {
                Diameter = 1,
                InnerDiameter = 0.8,
                StrokeThickness = 0,
                AngleSpan = 360,
                StartAngle = 0,
                InsideLabelFormat = null,
                OutsideLabelFormat = null,
            };
            ps2.Slices.Add(new PieSlice("", 20) { Fill = Color.Red.ToOxyColor() });
            ps2.Slices.Add(new PieSlice("", 20) { Fill = Color.Blue.ToOxyColor() });
            ps2.Slices.Add(new PieSlice("", 10));
            ps2.Slices.Add(new PieSlice("", 25) { Fill = Color.DarkOrange.ToOxyColor() });
            ps2.Slices.Add(new PieSlice("", 25) { Fill = Color.Accent.ToOxyColor() });
            model2.Series.Add(ps2);
    
    
            PlotModel model3 = new PlotModel();
            PieSeries ps3 = new PieSeries
            {
                Diameter = 1,
                InnerDiameter = 0.8,
                StrokeThickness = 0,
                AngleSpan = 360,
                StartAngle = 0,
                InsideLabelFormat = null,
                OutsideLabelFormat = null,
            };
            ps3.Slices.Add(new PieSlice("", 20) { Fill = Color.Red.ToOxyColor() });
            ps3.Slices.Add(new PieSlice("", 25) { Fill = Color.Blue.ToOxyColor() });
            ps3.Slices.Add(new PieSlice("", 20));
            ps3.Slices.Add(new PieSlice("", 10) { Fill = Color.DarkOrange.ToOxyColor() });
            ps3.Slices.Add(new PieSlice("", 25) { Fill = Color.Accent.ToOxyColor() });
            model3.Series.Add(ps3);
    

    In ViewCell:

                PlotView plot = new PlotView()
                {
                    Model = model3,
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    VerticalOptions = LayoutOptions.CenterAndExpand,
                    HeightRequest = 300,
                    WidthRequest = 300,
                };
    
                plot.SetBinding(PlotView.ModelProperty, new Binding("Model"));
    

    Class:

        public class Detail
        {
            public PlotModel Model { get; set; }
        }
    

    ListCollection

            //ObservableCollection<Detail> collection = new ObservableCollection<Detail>
            //{
            //  new Detail{Model=model1 },
            //  new Detail{Model=model2 },
            //  new Detail{Model = model3},
            //};
    

    you have to add this collection as a ItemsSource to ListView

    Monday, June 12, 2017 5:06 AM