2

There are dozens of issues about this particular problem, but none of the proposed solutions have worked for me. I cannot get OxyPlot to appear in iOS or Android. I've followed the setup instructions to add the various Init methods after Xamarin Forms init. What I have tried so far:

  • Adding HeightRequest + WidthRequest
  • Not putting it in a stack layout
  • Adding a dummy variable after init
  • Going to the latest unstable version via OxyPlot's nuget feed (https://www.myget.org/F/oxyplot)

I am using Xamarin Android version 25.4.0.2, Xamarin Forms 2.4.0.18342, and OxyPlot version 1.0.0.

Here's the XAML:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:oxy="clr-namespace:OxyPlot.Xamarin.Forms;assembly=OxyPlot.Xamarin.Forms"
        x:Class="Example.Stats"
        NavigationPage.HasNavigationBar="false">
    <ContentPage.Content>
        <AbsoluteLayout>  
            <oxy:PlotView Model="{Binding Model}"  
                  AbsoluteLayout.LayoutBounds="20,0,.9,.9" AbsoluteLayout.LayoutFlags="WidthProportional,HeightProportional" />  
        </AbsoluteLayout>  
    </ContentPage.Content>
</ContentPage>

And the partial class:

namespace Gatemaster
{
    public partial class Stats : ContentPage
    {
        public PlotModel Model { 
            get {
                var model = new PlotModel { Title = "World population by continent" };  
                var ps = new PieSeries  
                {        
                    StrokeThickness = .25,  
                    InsideLabelPosition = .25,  
                    AngleSpan = 360,  
                    StartAngle = 0  
                };  

                // http://www.nationsonline.org/oneworld/world_population.htm  
                // http://en.wikipedia.org/wiki/Continent  
                ps.Slices.Add(new PieSlice("Africa", 1030) { IsExploded = false });  
                ps.Slices.Add(new PieSlice("Americas", 929) { IsExploded = false });  
                ps.Slices.Add(new PieSlice("Asia", 4157));  
                ps.Slices.Add(new PieSlice("Europe", 739) { IsExploded = false });  
                ps.Slices.Add(new PieSlice("Oceania", 35) { IsExploded = false });  
                model.Series.Add(ps);
                return model;
            } 
            private set { 

            } 
        }

        public Stats()
        {
            InitializeComponent();
        }
    }
}
5
  • 1
    you don't appear to be setting your BindingContext Commented Oct 25, 2017 at 17:31
  • @Jason Is that required in this instance? I've been able to bind to properties on the partial class before without setting it. Commented Oct 25, 2017 at 17:38
  • 1
    AFAIK, you can either set it explicitly or inherit it, but it has to be set somewhere Commented Oct 25, 2017 at 17:41
  • 1
    Have you tried setting vertical and horizontal options to centre and the height/width request at the same time? I've got mine inside a grid and this works for me: <oxy:PlotView x:Name="GraphPanel" Model="{Binding ChartData}" Grid.Row="3" VerticalOptions="Center" HorizontalOptions="Center" WidthRequest="500" HeightRequest="300" /> Commented Oct 25, 2017 at 17:44
  • @Jason: Welp, you were right. BindingContext = this; in the initializer made the graph appear. Commented Oct 25, 2017 at 17:51

1 Answer 1

1

As per @Jason, I missed setting BindingContext. I find it incredibly odd that an error wasn't being thrown about a missing property...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.