2

我正在尝试将点动态添加到 a LineSeries,但在使绘图无效后它不会显示。使用直接来自 NuGet 的最新 OxyPlot 版本 2014.1.301.1。如果我将 设置ItemSource为新列表,它会起作用,但编辑 Items 属性什么也不做。

XAML:

<Window x:Class="SparrowTesting.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sparrow="http://sparrowtoolkit.codeplex.com/wpf"
         xmlns:oxy="http://oxyplot.codeplex.com"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>
        <oxy:Plot Title="OxyTest" x:Name="chart">
            <oxy:Plot.Series>
                <oxy:LineSeries></oxy:LineSeries>
            </oxy:Plot.Series>
        </oxy:Plot>
        <Button Grid.Row="1" x:Name="button1" Click="button1_Click">
            <TextBlock>GO</TextBlock>
        </Button>
    </Grid>
</Window>

代码:

 chart.Series[0].Items.Add(new DataPoint(1, 2));
 chart.InvalidatePlot(true);//Does nothing
4

2 回答 2

3

忽略该Items属性并仅使用ItemSource,然后它就像一个魅力。

chart.Series[0].ItemsSource = new List<DataPoint>();
(chart.Series[0].ItemsSource as List<DataPoint>).Add(new DataPoint())
//Profit
于 2014-05-15T12:24:51.843 回答
0

我无法工作chart.InvalidatePlot(true);,但chart.Series.Clear();工作得很好。我会尝试将它放在您的新数据点之前,如下所示:

chart.Series.Clear(); 
chart.Series[0].Items.Add(new DataPoint(1, 2));
于 2016-06-20T20:51:40.627 回答