3

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 Answers2

5

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.

ChronoZZ
  • 161
  • 3
  • 8
  • For several thousands of values it will take along time to add all values through a loop. Is it possible to add two lists directly to the ChartValues ? – krambambuli Apr 27 '23 at 10:58
  • 1
    You may want to create a separate question for this. A untested thought is that you can call .AddRange on your main list for each of your other lists. You will need to create lists of ObservablePoint prior to making the call to AddRange though. – ChronoZZ Apr 28 '23 at 11:58
1

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.

Yvonnila
  • 635
  • 1
  • 5
  • 22