'How can I update the plot in oxyplot?

I am using oxyplot package in WPF(.NET 6) with Prism FrameWork, but there is a question about the updating of the plot.

I write the code in the command method which is binding with a button, but the plot cannot present.

The code is PlotRadiation which is added in PlotRadiationCommand.

double[] xList = Array.ConvertAll(Enumerable.Range(-180, 361).ToArray(), s => { return (double)s; });

List<Complex> radiationList = RadiationCalculator.GetRadiationData(N, lambda, In, d, phi); // 计算方向图数据

double[] yList = new double[361];
for (int i = 0; i < 361; i++)
{
    yList[i] = radiationList[i].Magnitude;
}

LineSeries line = new LineSeries();
for(int i = 0; i < 361; i++)
{
    line.Points.Add(new DataPoint(xList[i], yList[i]));
}

GraphModel.Series.Add(line);

The xaml code is:

<oxy:PlotView Grid.Column="1" Model="{Binding GraphModel}" />
<Button Name="plotFig_button" Grid.Row="1"
                        Margin="20,0,20,0"
                        VerticalAlignment="Center"
                        Command="{Binding PlotRadiationCommand}"
                        Content="plot" />

Furthermore, how can i find the detailed document of the oxyplot, the official document of the oxyplot is skechy.



Solution 1:[1]

I think you should make the GraphModel property an observable property so that when it's changed it notifies the application and the changes occur in the view. Try doing something like this

private IList<DataPoint> dataPoints;
public IList<DataPoint> DataPoints 
{
    get 
    { 
         return dataPoints;
    }
    set 
    {
         dataPoints = value;
         OnPropertyChanged();
    }
}

I don't know what exactly GraphModel is, however, you can make this code work for your case by changing some variable names.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1