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

How to Set a Fixed Number of X-Axis Labels in LiveCharts2? #1099

Closed
beto-rodriguez opened this issue Jul 6, 2023 Discussed in #1098 · 4 comments
Closed

How to Set a Fixed Number of X-Axis Labels in LiveCharts2? #1099

beto-rodriguez opened this issue Jul 6, 2023 Discussed in #1098 · 4 comments

Comments

@beto-rodriguez
Copy link
Owner

Discussed in #1098

Originally posted by xiaotebie July 5, 2023
Hello,

I am currently using LiveCharts2 in my WPF application and I have a question about setting a fixed number of x-axis labels.

In my application, I want to display a fixed number of labels on the x-axis, regardless of the number of data points in my series. For example, I want to display 10 labels on the x-axis, but I might only have 7 data points in my series.

I tried to set the Labels property of the Axis object to a string array of 10 elements, but it didn't work as expected. The x-axis still only showed labels for the 7 data points in my series, and it didn't display the remaining 3 labels.

Here is a snippet of my code:

public ISeries[] Series { get; set; } = new ISeries[]
    {
        new LineSeries<double>
        {
            Values = new double[] { 2, 1, 3, 5, 3, 4, 6 },
            Fill = null
        }
    };

public Axis[] XAxes { get; set; }
    = new Axis[]
    {
        new Axis
        {
            Name = "X Axis",
            NamePaint = new SolidColorPaint(SKColors.Black),
            LabelsPaint = new SolidColorPaint(SKColors.Blue),
            TextSize = 10,
            Labels = new string[] { "1", "2", "3", "4" ,"5","6","7","8","9","10"},
            SeparatorsPaint = new SolidColorPaint(SKColors.LightSlateGray) { StrokeThickness = 2 }
        }
    };

Is there a way to achieve this in LiveCharts2? Any help would be greatly appreciated.

Thank you in advance!

@beto-rodriguez
Copy link
Owner Author

Hi! this is not implemented yet.

This is a necessary, the library needs to provide a solution for this, I have seen a couple of similar issues related to this.
I transferred the discussion to an issue, so we can track the implementation of this.

@beto-rodriguez
Copy link
Owner Author

This is already implemented in the beta.810 version, thanks for the report, here is an example:

https://github.com/beto-rodriguez/LiveCharts2/blob/master/samples/ViewModelsSamples/Axes/CustomSeparatorsInterval/ViewModel.cs

@daltzctr
Copy link

daltzctr commented Aug 1, 2023

What if the X axis labels are not known at compile time? Basically, if the X axis is time in a live chart?

@xiaotebie
Copy link

This is already implemented in the beta.810 version, thanks for the report, here is an example:

https://github.com/beto-rodriguez/LiveCharts2/blob/master/samples/ViewModelsSamples/Axes/CustomSeparatorsInterval/ViewModel.cs

Thank you so much for your help!

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

No branches or pull requests

3 participants