beto-rodriguez / LiveCharts2

Simple, flexible, interactive & powerful charts, maps and gauges for .Net, LiveCharts2 can now practically run everywhere Maui, Uno Platform, Blazor-wasm, WPF, WinForms, Xamarin, Avalonia, WinUI, UWP.
https://livecharts.dev
MIT License
4.39k stars 574 forks source link

FontFamily="{StaticResource myFont}" not work #1518

Closed mehdininja closed 2 months ago

mehdininja commented 6 months ago

Setting the font does not work in this way,

<Grid>
    <lvc:CartesianChart Series="{Binding Series}" XAxes="{Binding XAxes}" YAxes="{Binding YAxes}" VisualElements="{Binding VisualElements}" TooltipPosition="Hidden" FontFamily="{StaticResource myFont}" FontWeight="Bold" Typography.StylisticSet4="True"/>
</Grid>

also in the C# code FontFamily is string property.

LabelsPaint = new SolidColorPaint(SKColors.Black) {FontFamily="", SKFontStyle = new SKFontStyle(SKFontStyleWeight.Bold, SKFontStyleWidth.Normal, SKFontStyleSlant.Upright)},

So how to apply FontFamily="{StaticResource myFont}" ?

beto-rodriguez commented 2 months ago

Hello

The FontFamily that you are binding there is not a properly of this library, it comes from the type of the control inherits from (ContentView) this property is defined by MAUI and I am not completely sure what is the usage of it in this context.

This library uses SkiaSharp to render things, so things inside a chart are not part of MAUI, fonts are set on Series or Axes, for example:

https://github.com/beto-rodriguez/LiveCharts2/blob/5836c7fe73fe49cead353c50691d3db735dff662/tests/LiveChartsCore.UnitTesting/SeriesTests/LineSeriesTest.cs#L245

This is the way fonts are defined in SkiaSharp, I know docs could be better here.

I hope this helps!