Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Charts dont display on Xamarin Forms UWP #63

Open
leedjones opened this issue Jun 27, 2017 · 6 comments
Open

Charts dont display on Xamarin Forms UWP #63

leedjones opened this issue Jun 27, 2017 · 6 comments

Comments

@leedjones
Copy link

Steps to reproduce

  1. Create a new Xamarin Forms Blank App
  2. Add OxyPlot libraries via Nuget (Oxyplot.Xamarin.Forms) as per documentation
  3. Add initialization code to each project as per the documentation
  4. Generate a graph data using the code behind and bind to it in the XAML. e.g.
<?xml version="1.0" encoding="utf-8" ?>
<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"
             xmlns:local="clr-namespace:OxyPlotTestApp"
             x:Class="OxyPlotTestApp.MainPage">

    <AbsoluteLayout>
        <oxy:PlotView Model="{Binding PieModel}" AbsoluteLayout.LayoutBounds="20,0,.9,.9" 
                      AbsoluteLayout.LayoutFlags="WidthProportional,HeightProportional" />
    </AbsoluteLayout>

</ContentPage>
namespace OxyPlotTestApp
{
    public class PieViewModel
    {
        public PlotModel PieModel { get; set; }

        public PieViewModel()
        {
            PieModel = CreatePieChart();

        }

        private PlotModel CreatePieChart()
        {
            var model = new PlotModel { Title = "World Population By Content" };
            var ps = new PieSeries
            {
                StrokeThickness = .25,
                InsideLabelPosition = 0.25,
                AngleSpan = 360,
                StartAngle = 0
            };
            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;
        }

    }
    public partial class MainPage : ContentPage
    {
        public PieViewModel vm { get; set; }
        public MainPage()
        {
            InitializeComponent();
            vm = new PieViewModel();
            this.BindingContext = vm;
        }

    }
}
  1. Run the UWP version of the application

Platform: Xamarin Forms UWP
.NET version:

Expected behaviour

Graph should display as per other platforms

Actual behaviour

Nothing is displayed on screen. According to this thread on StackOverflow another user can see this but if they resize the window the chart renders. However, this does not happen for me.

Tested on two machines (custom built desktop and a Surface Pro 4) and experience the same behaviour. Tested on Android, both the emulator and a physical device, and both work as expected, so it would seem to be just the UWP version.

@pulla2908
Copy link

Is this issue now fixed? Any work around?

@leedjones
Copy link
Author

@pulla2908 not that I am aware of and no workaround either :(

@pulla2908
Copy link

pulla2908 commented Sep 26, 2017

@leedjones I am one step further!

First of all I got the solution from here: Xamarin Formus

This is my setup:

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <StackLayout Grid.Row="0" 
                     Padding="10">
            <Picker ItemsSource="{Binding Periodes}" 
                    ItemDisplayBinding="{Binding DisplayName}"
                    SelectedItem="{Binding SelectedPeriode}"
                    SelectedIndexChanged="Periode_OnSelectedIndexChanged"
                    HorizontalOptions="FillAndExpand">
            </Picker>
        </StackLayout>

        <oxy:PlotView Model="{Binding PlotModel}" Grid.Row="1"
                      VerticalOptions="FillAndExpand" 
                      HorizontalOptions="FillAndExpand" >
        </oxy:PlotView>
    </Grid>

On Android it was rendering everytime. On iOS and UWP never. Then I set the PlotView like this:
VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"

This change made it working immediately on iOS! But on UWP it was not rendering at all, but then if I resized the windows the rendering was done!

Next step: For UWP I upgraded to OxyPlot.Xamarin.Forms/1.1.0-unstable0011. I run the app again and rendering was done immediately!

Hope that helps!

br
Thomas

@pulla2908
Copy link

In addition to RELEASE) The compiler does some optimization. Therefore some assemblies are missing. To fix this I did following:

var assembliesToInclude = new List<Assembly>
{
	typeof(OxyPlot.Xamarin.Forms.Platform.UWP.PlotViewRenderer).GetTypeInfo().Assembly
};
Xamarin.Forms.Forms.Init(e, assembliesToInclude);
OxyPlot.Xamarin.Forms.Platform.UWP.PlotViewRenderer.Init();

Note: This is only necessary for RELEASE, but not for DEBUG.

@AloysiusParedes
Copy link

@leedjones I am one step further!

First of all I got the solution from here: Xamarin Formus

This is my setup:

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <StackLayout Grid.Row="0" 
                     Padding="10">
            <Picker ItemsSource="{Binding Periodes}" 
                    ItemDisplayBinding="{Binding DisplayName}"
                    SelectedItem="{Binding SelectedPeriode}"
                    SelectedIndexChanged="Periode_OnSelectedIndexChanged"
                    HorizontalOptions="FillAndExpand">
            </Picker>
        </StackLayout>

        <oxy:PlotView Model="{Binding PlotModel}" Grid.Row="1"
                      VerticalOptions="FillAndExpand" 
                      HorizontalOptions="FillAndExpand" >
        </oxy:PlotView>
    </Grid>

On Android it was rendering everytime. On iOS and UWP never. Then I set the PlotView like this:
VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"

This change made it working immediately on iOS! But on UWP it was not rendering at all, but then if I resized the windows the rendering was done!

Next step: For UWP I upgraded to OxyPlot.Xamarin.Forms/1.1.0-unstable0011. I run the app again and rendering was done immediately!

Hope that helps!

br
Thomas

Is there a way to fix this in the current stable version? I am getting the exact same thing (Building for UWP with Xamarin.Forms)

@markbangert
Copy link

I have exactly the same issue with UWP - the graph displays upon resizing... :(

Anybody got some more input how to resolve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants