oxyplot-xamarin
oxyplot-xamarin copied to clipboard
Charts dont display on Xamarin Forms UWP
Steps to reproduce
- Create a new Xamarin Forms Blank App
- Add OxyPlot libraries via Nuget (Oxyplot.Xamarin.Forms) as per documentation
- Add initialization code to each project as per the documentation
- 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;
}
}
}
- 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.
Is this issue now fixed? Any work around?
@pulla2908 not that I am aware of and no workaround either :(
@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
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.
@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)
I have exactly the same issue with UWP - the graph displays upon resizing... :(
Anybody got some more input how to resolve this?