Open
Description
I am using the code provided here:
https://github.com/oxyplot/oxyplot/tree/develop/Source/OxyPlot.ImageSharp
to export chart model to PNG, i try several examples i have and allways get some errors, i will try to upload them all.
I have this XAML for a pie chart:
<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="Charts.PieEx">
<AbsoluteLayout>
<Button Text="Capture"
x:Name="btnCapture"
Clicked="BtnCapture_Clicked"
WidthRequest="50"
HeightRequest="30"
FontSize="5"
VerticalOptions="Start"
HorizontalOptions="CenterAndExpand"></Button>
<oxy:PlotView Model="{Binding PieModel}"
x:Name="rangeChartView"
BackgroundColor="White"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
AbsoluteLayout.LayoutBounds="10,30,.9,.9"
AbsoluteLayout.LayoutFlags="WidthProportional,HeightProportional" />
</AbsoluteLayout>
</ContentPage>
Then in the .cs i have this code when button is pressed:
private void BtnCapture_Clicked(object sender, EventArgs e)
{
using (Stream stream = new MemoryStream())
{
var exporter = new PngExporter();
exporter.Background = rangeChartView.Model.Background;
exporter.Height = Convert.ToInt32(rangeChartView.Model.Height);
exporter.Width = Convert.ToInt32(rangeChartView.Model.Width);
exporter.Resolution = 180;
exporter.Export(rangeChartView.Model, stream);
Console.WriteLine(stream);
}
this.rangeChartView.Model);
}
And create the pie chart content here:
private PlotModel CreatePieChart()
{
var model = new PlotModel { Title = "Pie Chart" };
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;
}
When i run on Android i get an exception on the class PngRenderingContext:
OxyPlot exception: One or more errors occurred. (Segoe UI could not be found) (Arial could not be found)
Seems that it couldn't fin de font when the code is reached on method GetFamilyOrFallbackOrThrow:
family = SystemFonts.Find(fontFamily);
In the class is defined:
static readonly string FallbackFontFamily = "Arial";`
Any clue why this is happening?