Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LiveCharts - plotting x&y from lists

I have four lists (x1List, y1List, x2List, y2List) which hold 1000 values each, i want to plot these lists as x & y values using LiveCharts.

i understand how to plot the y values using;

            new LineSeries
            {
                Title = "Series1",
                Values = y1List.AsChartValues(),
                PointGeometry = null
            },

            new LineSeries
            {
                Title = "Series2",
                Values = y2List.AsChartValues(),
                PointGeometry = null
            },

I don't understand how to apply the x values to their respective series.

I'm new to c# so apologies if this is something simple i am overlooking.


2 Answers

You can use an ObserablePoint object to store an X and Y value. Then you can create a ChartValues<ObservablePoint> that will plot what I'm thinking you want to see. Make sure to include the statement for LiveCharts.Defualts namespace;

using LiveCharts.Defaults;

ChartValues<ObservablePoint> List1Points = new ChartValues<ObservablePoint>();

For(int i = x1List, i < x1List.Count, i++)
{
    List1Points.Add(new ObservablePoint 
    { 
        X=x1List[i], 
        Y=y1List[i]
    });
}

Hopefully something like that will work for you.

like image 119
ChronoZZ Avatar answered Nov 22 '25 14:11

ChronoZZ


Have a look at this example: https://lvcharts.net/App/examples/v1/wpf/Multiple%20Axes

You can Add 2 X-Axis to your chart, set the Labels properties of these axes to x1List and x2List.

Then, by assigning the values to your series, you can set the Property ScalesXAt of your series to 0 (for the first axis), or 1 (for the second axis).

I hope it helps.

Let me know if you had any questions about it.

like image 38
Yvonnila Avatar answered Nov 22 '25 15:11

Yvonnila