Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axis Breaks When Chart Has Null Data #1721

Open
c0nstexpr opened this issue Dec 6, 2024 · 2 comments
Open

Axis Breaks When Chart Has Null Data #1721

c0nstexpr opened this issue Dec 6, 2024 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@c0nstexpr
Copy link

c0nstexpr commented Dec 6, 2024

Similar to #1294
I edit the view model implementation of Axes/Shared example in the project.

  • Replace data type from int to TimeSpanPoint (or any other class type)
  • Delete Values property assign for both series, only null collection
  • Start the app, zoom out any chart then we got NaN on X axis

ViewModel.cs

using SkiaSharp;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;
using LiveChartsCore.Drawing;
using LiveChartsCore.Measure;
using LiveChartsCore.Defaults;

public class ViewModel
{
    public ISeries[] SeriesCollection1 { get; set; }
    public ISeries[] SeriesCollection2 { get; set; }
    public Axis[] X1 { get; set; }
    public Axis[] X2 { get; set; }
    public Margin DrawMargin { get; set; }

    public ViewModel()
    {
        SeriesCollection1 = new ISeries[] { new LineSeries<TimeSpanPoint> {  } };
        SeriesCollection2 = new ISeries[] { new ColumnSeries<TimeSpanPoint> {  } };

        // ideally, when sharing an axis, you should set the // mark
        // initial limits for all the axes involved. // mark
        var padding = 3;
        var start = 0 - padding;
        // var end = values1.Length - 1 + padding;

        X1 = new Axis[]
        {
            new Axis
            {
                MinLimit = 1,
                MaxLimit = 2,
                CrosshairLabelsBackground = SKColors.OrangeRed.AsLvcColor(),
                CrosshairLabelsPaint = new SolidColorPaint(SKColors.White),
                CrosshairPaint = new SolidColorPaint(SKColors.OrangeRed.WithAlpha(50), 4),
                CrosshairPadding = new Padding(8),
                Labeler = value => value.ToString("N2")
            }
        };

        X2 = new Axis[]
        {
            new Axis
            {
                MinLimit = 1,
                MaxLimit = 2,
                CrosshairPaint = new SolidColorPaint(SKColors.OrangeRed.WithAlpha(50), 4)
            }
        };

        SharedAxes.Set(X1[0], X2[0]);

        // Force the chart to use 70px margin on the left, this way we can align both charts Y axes. // mark
        DrawMargin = new Margin(70, Margin.Auto, Margin.Auto, Margin.Auto);
    }        
}
@c0nstexpr c0nstexpr changed the title Axis Breaks When Chart Has no Data Axis Breaks When Chart Has No Data Dec 6, 2024
@c0nstexpr
Copy link
Author

c0nstexpr commented Dec 6, 2024

I test several times, the problem also happens when the Value prop of TimeSpanPoint in both series has null value.

SeriesCollection1 = new ISeries[]
{
    new LineSeries<TimeSpanPoint>
    {
        Values = new TimeSpanPoint[] 
        {
            new TimeSpanPoint() { TimeSpan = TimeSpan.Zero, Value = null },
        }
    }
};
SeriesCollection2 = new ISeries[]
 {
    new LineSeries<TimeSpanPoint>
    {
        Values = new TimeSpanPoint[]
        {
            new TimeSpanPoint() { TimeSpan = TimeSpan.Zero, Value = null },
        }
    }
};

@c0nstexpr c0nstexpr changed the title Axis Breaks When Chart Has No Data Axis Breaks When Chart Has Null Data Dec 7, 2024
beto-rodriguez added a commit that referenced this issue Dec 24, 2024
@beto-rodriguez
Copy link
Owner

Thanks for the report, this is fixed with the referenced commit and will be included in the next release of the library.

@beto-rodriguez beto-rodriguez added the bug Something isn't working label Dec 24, 2024
@beto-rodriguez beto-rodriguez added this to the rc-5 milestone Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants