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.38k stars 572 forks source link

Chart not rendered if i set "LegendTextSize" with Library ver. >= 2.0.0-rc3 (MAUI) #1694

Open XamMattia83 opened 2 weeks ago

XamMattia83 commented 2 weeks ago

Describe the bug Hello!

I have a CartesianChart (with Column Series) with a "customized" legend. If i set any value on "LegendTextSize" the chart will not appear so, for now, i need to remove it.

Everything was working till ver. 2.0.0-rc2 included.

Here my XAML:

                    <lvc:CartesianChart
                        Grid.Row="1"
                        AnimationsSpeed="00:00:00.100"
                        HeightRequest="270"
                        LegendBackgroundPaint="{Binding LegendBackground}"
                        LegendPosition="Bottom"
                        LegendTextPaint="{Binding LegendTextPaint}"
                        LegendTextSize="8"
                        Series="{Binding Series}"
                        XAxes="{Binding XAxes}"
                        YAxes="{Binding YAxes}" />

View Model:

    public ObservableCollection<ISeries> Series { get; set; }                       
    public Axis[] XAxes { get; set; }                                           
    public Axis[] YAxes { get; set; }
    public SolidColorPaint LegendTextPaint { get; set; } = new SolidColorPaint
    {
        Color = SKColors.LightGray,
    };

    public SolidColorPaint LegendBackground { get; set; } = new SolidColorPaint
    {
        Color = SKColors.Transparent,
    };

    private ObservableValue BarAhScarica = new(0);
    private ObservableValue BarAhAutoScarica = new(0);
    private ObservableValue BarAhCarica = new(0);
    private ObservableValue BarAhReflow = new(0);

// ..more code here //

//Inside the View model Constructor:

        Series =
        [
            new ColumnSeries<ObservableValue>
            {
                Name = AppResources.Scarica,
                Values = new ObservableCollection<ObservableValue> {BarAhScarica},
                DataLabelsPaint = new SolidColorPaint(SKColors.Red),
                DataLabelsSize = 10,                                                                            
                DataLabelsFormatter = (point) => point.Coordinate.PrimaryValue.ToString("F1")+ " Ah",          
                Fill = new SolidColorPaint(SKColors.Red),
                MaxBarWidth = 100,
                Padding = 10,
                DataLabelsPadding = new Padding(5,5),
                ClippingMode = ClipMode.None,
            },

            new ColumnSeries<ObservableValue>
            {
                Name = AppResources.AutoDisch,
                Values = new ObservableCollection<ObservableValue> {BarAhAutoScarica},
                DataLabelsPaint = new SolidColorPaint(SKColors.Orange),
                DataLabelsSize = 10,
                DataLabelsFormatter = (point) => point.Coordinate.PrimaryValue.ToString("F1") + " Ah",
                Fill = new SolidColorPaint(SKColors.Orange),
                MaxBarWidth = 100,
                Padding = 10,
                DataLabelsPadding = new Padding(5,5),
                ClippingMode = ClipMode.None,
            },

            new ColumnSeries<ObservableValue>
            {
                Name = AppResources.Carica,
                Values = new ObservableCollection<ObservableValue> {BarAhCarica},
                DataLabelsPaint = new SolidColorPaint(SKColors.LightGreen),
                DataLabelsSize = 10,
                DataLabelsFormatter = (point) => point.Coordinate.PrimaryValue.ToString("F1")+ " Ah",
                Fill = new SolidColorPaint(SKColors.LightGreen),
                MaxBarWidth = 100,
                Padding = 10,
                DataLabelsPadding = new Padding(5,5),
                ClippingMode = ClipMode.None,
            },

            new ColumnSeries<ObservableValue>
            {
                Name = AppResources.Reflow,
                Values = new ObservableCollection<ObservableValue> {BarAhReflow},
                DataLabelsPaint = new SolidColorPaint(SKColors.DodgerBlue),
                DataLabelsSize = 10,
                DataLabelsFormatter = (point) => point.Coordinate.PrimaryValue.ToString("F1") + " Ah",
                Fill = new SolidColorPaint(SKColors.DodgerBlue),
                MaxBarWidth = 100,
                Padding = 10,
                DataLabelsPadding = new Padding(5,5),
                ClippingMode = ClipMode.None,
            },
        ];

        XAxes =
        [
            new Axis
            {
                Labels = ["","","",""],
            }
        ];

        YAxes =
        [
            new Axis
            {
                Labels = [""]
            }
        ];

Smartphone (please complete the following information):

Current Lib tested: 2.0.0-rc4.5