问题
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.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/45783192/livecharts-plotting-xy-from-lists