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

While setting properties MinStep and ForceStepToMin, CartesianChart not appearing #1691

Open vadimffe opened 2 weeks ago

vadimffe commented 2 weeks ago

Describe the bug I am using CartesianChart in this way

XAML part:

        <lvc:CartesianChart Series="{Binding MyChartData}" 
                            XAxes="{Binding ChartXAxes }" 
                            YAxes="{Binding ChartYAxes }" 
                            TooltipBackgroundPaint="{Binding TooltipBackgroundPaint}"
                            TooltipTextPaint="{Binding TooltipTextPaint}"
                            TooltipTextSize="10">
        </lvc:CartesianChart>

ViewModel part:

private void InitializeChartXAxes()
{
    this.ChartXAxes = new Axis[]
    {
        new Axis
        {
            Labeler = value =>
            {
                try
                {
                    if (value is double doubleValue)
                    {
                        // Convert double to month value (1-12)
                        int monthValue = (int)doubleValue;

                        // Validate the month value
                        if (monthValue >= 1 && monthValue <= 12)
                        {
                            // Get month name
                            DateTime dateTime = new DateTime(1, monthValue, 1);
                            return dateTime.ToString("MMM"); // Returns abbreviated month name (Jan, Feb, etc.)
                        }
                    }

                    return "N/A";
                }
                catch (Exception ex)
                {
                    this.Logger.LogWarning($"Exception: {ex}");
                    return "Error";
                }
            },

            LabelsPaint = new SolidColorPaint(SKColors.White),

            // Each unit represents one month
            UnitWidth = TimeSpan.FromDays(30).Ticks,

            // Minimum step between labels is one month
            MinStep = TimeSpan.FromDays(30).Ticks,
            ForceStepToMin = true,
        },
    };
}

Note that some months can have zero values, should be also visible.

After update to 2.0.0-rc3.3 and v2.0.0-rc4 part below makes chart not appearing.

            MinStep = TimeSpan.FromDays(30).Ticks,
            ForceStepToMin = true,

However in 2.0.0-rc2 everything is working fine with my current setup. So in newest versions if I remove MinStep and ForceStepToMin, chart is appearing, but then I am not able to set these values properly. I have not yet investigated all the recent changes in details. Just reporting an issue I am currently facing.

Desktop (please complete the following information):

XamMattia83 commented 2 weeks ago

Hello, i can confirm...i have the same issue here on MAUI - tested on Android and iOS real devices