c# - How do I create a graph with x, y updated values? - Stack Overflow

admin2025-04-16  5

How do I create a graph where the x, y values are updated?
I tried it as below. The simple graph works. But the x,y graph does not. How can I create an x,y graph this way?

C# code simple graph:

List<int> ValuesPoints = new List<int>();
for (int x = 0; x < 10; x ++)
    ValuesPoints.Add(x);
            
ObservableCollection<ISeries> seriesCollection = new ObservableCollection<ISeries>();
grfArbeitsfenster2.Series = seriesCollection;

seriesCollection.Add(new LineSeries<int>
{
    Values = ValuesPoints
});

C# code x,y graph

List<ObservablePoint> ValuesPoints = new List<ObservablePoint>();
for (int x = 0; x < 10; x++)
    ValuesPoints.Add(new ObservablePoint(x, x+1));

ObservableCollection<ISeries> seriesCollection = new ObservableCollection<ISeries>();
grfArbeitsfenster2.Series = seriesCollection;

seriesCollection.Add(new LineSeries<ObservablePoint>
{
    Values = ValuesPoints  
});

Wpf Code:

<lvc:CartesianChart x:Name="grfArbeitsfenster2" 
                    Series="{Binding Series}" 
                    Width="700" 
                    Height="350" 
                    Margin="183,101,96.2,1885" />

How do I create a graph where the x, y values are updated?
I tried it as below. The simple graph works. But the x,y graph does not. How can I create an x,y graph this way?

C# code simple graph:

List<int> ValuesPoints = new List<int>();
for (int x = 0; x < 10; x ++)
    ValuesPoints.Add(x);
            
ObservableCollection<ISeries> seriesCollection = new ObservableCollection<ISeries>();
grfArbeitsfenster2.Series = seriesCollection;

seriesCollection.Add(new LineSeries<int>
{
    Values = ValuesPoints
});

C# code x,y graph

List<ObservablePoint> ValuesPoints = new List<ObservablePoint>();
for (int x = 0; x < 10; x++)
    ValuesPoints.Add(new ObservablePoint(x, x+1));

ObservableCollection<ISeries> seriesCollection = new ObservableCollection<ISeries>();
grfArbeitsfenster2.Series = seriesCollection;

seriesCollection.Add(new LineSeries<ObservablePoint>
{
    Values = ValuesPoints  
});

Wpf Code:

<lvc:CartesianChart x:Name="grfArbeitsfenster2" 
                    Series="{Binding Series}" 
                    Width="700" 
                    Height="350" 
                    Margin="183,101,96.2,1885" />
Share Improve this question edited Feb 3 at 8:19 Sir Rufo 19.1k2 gold badges44 silver badges78 bronze badges asked Feb 3 at 6:17 lechu2025lechu2025 1
Add a comment  | 

1 Answer 1

Reset to default -1

Just going off of the documentation of the livecharts library, but have you tried binding to an ObservableCollection of ICartesianSeries rather than an ObservableCollection of ISeries?

The CartesianChart control is a 'ready to go' control to create plots using the Cartesian coordinate system, To get started all you need to do is assign the Series property with a collection of ICartesianSeries.

Link for Reference

转载请注明原文地址:http://anycun.com/QandA/1744777180a87479.html