diff --git a/src/LiveChartsCore/Chart.cs b/src/LiveChartsCore/Chart.cs index 9f3cea61c..7cdb347a1 100644 --- a/src/LiveChartsCore/Chart.cs +++ b/src/LiveChartsCore/Chart.cs @@ -589,6 +589,9 @@ protected void DrawLegend(IChartSeries[] seriesInLegend) if (LegendPosition is LegendPosition.Top or LegendPosition.Bottom) ControlSize = new(ControlSize.Width, ControlSize.Height - imageLegend.Size.Height); + // reset for cases when legend is hidden or changes postion + Canvas.StartPoint = new LvcPoint(0, 0); + Legend.Draw(this); PreviousLegendPosition = LegendPosition; diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKDefaultLegend.cs b/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKDefaultLegend.cs index 0688031a9..a3a3d2bb3 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKDefaultLegend.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKDefaultLegend.cs @@ -142,16 +142,19 @@ private void BuildLayout(Chart chart) _stackPanel ??= new StackPanel { Padding = new Padding(0), - Orientation = _orientation, HorizontalAlignment = Align.Start, VerticalAlignment = Align.Middle, - BackgroundPaint = BackgroundPaint }; + _stackPanel.Orientation = _orientation; + _stackPanel.BackgroundPaint = BackgroundPaint; + _toRemoveSeries = new List>(_stackPanel.Children); foreach (var series in chart.ChartSeries) { + if (!series.IsVisibleAtLegend) continue; + var seriesMiniatureVisual = GetSeriesVisual(series); _ = _toRemoveSeries.Remove(seriesMiniatureVisual); }