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

CartesianChart DateTimePoint bug: When Series have no values, Labeler in Axis throws ArgumentOutOfRangeException #629

Closed
felinepunch opened this issue Sep 17, 2022 · 4 comments

Comments

@felinepunch
Copy link

felinepunch commented Sep 17, 2022

Describe the bug
System.ArgumentOutOfRangeException: 'Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. Arg_ParamName_Name' is thrown when Series have no value.

The value of Labeler is -2000000000000 and new DateTime((long) value) throws exception.

environment: WinUI 3, Windows 10

public IEnumerable<ICartesianAxis> XAxes { get; set; } = new Axis[]
{
            new Axis
            {
                Labeler = value => new DateTime((long) value).ToString("MMMM dd"),
                LabelsRotation = 15,

                // when using a date time type, let the library know your unit 
                UnitWidth = TimeSpan.FromDays(1).Ticks, 

                // if the difference between our points is in hours then we would:
                // UnitWidth = TimeSpan.FromHours(1).Ticks,

                // since all the months and years have a different number of days
                // we can use the average, it would not cause any visible error in the user interface
                // Months: TimeSpan.FromDays(30.4375).Ticks
                // Years: TimeSpan.FromDays(365.25).Ticks

                // The MinStep property forces the separator to be greater than 1 day.
                MinStep = TimeSpan.FromDays(1).Ticks
            }
};

var series = new ColumnSeries<DateTimePoint>
{
    TooltipLabelFormatter = (chartPoint) => $"{new DateTime((long)chartPoint.SecondaryValue):MMMM dd}: {chartPoint.PrimaryValue}",
    Values = new ObservableCollection<DateTimePoint>
    {
//                    new DateTimePoint(new DateTime(2021, 1, 1), 3),
        // notice we are missing the day new DateTime(2021, 1, 2)
        //new DateTimePoint(new DateTime(2021, 1, 3), 6),
        //new DateTimePoint(new DateTime(2021, 1, 4), 5),
        //new DateTimePoint(new DateTime(2021, 1, 5), 3),
        //new DateTimePoint(new DateTime(2021, 1, 6), 5),
        //new DateTimePoint(new DateTime(2021, 1, 7), 8),
        //new DateTimePoint(new DateTime(2021, 1, 8), 6)
    },
    Fill = null,
};
@ehnajafi
Copy link

ehnajafi commented Oct 1, 2022

Try checking to see if value < 0 and if so set date to a default value.

Labeler = value => value >0 ? $"{new DateTime((long)value):MMMM dd}" : $"{DateTime.Now: MMMM dd}";

beto-rodriguez added a commit that referenced this issue Oct 5, 2022
@beto-rodriguez
Copy link
Owner

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

@danielgruethling
Copy link

danielgruethling commented Oct 26, 2022

The same exception gets thrown for me when I move the crosshair to the edge of an Axis using DateTimePoint in their Labeler. Also if I try to zoom on the Axis.

System.ArgumentOutOfRangeException: "Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. Arg_ParamName_Name"

But only if there are no points in the Series. So I thought I'd try to answer on this issue. I can also open a new issue if needed.

I am using WinUI3, Win10 and beta514

beto-rodriguez added a commit that referenced this issue Nov 24, 2022
@beto-rodriguez
Copy link
Owner

The referenced commit fixes that issue @danielgruethling, this fix will be included in the next version of the library, thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants