首页 文章

OxyPlot InvalidatePlot不刷新数据

提问于
浏览
2

我正在尝试动态地将点添加到 LineSeries ,但是在使绘图无效后它不会显示 . 使用最新的OxyPlot版本2014.1.301.1,直接来自NuGet . 如果我将 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

2 回答

  • 3

    忽略 Items 属性并仅使用 ItemSource ,它就像一个魅力 .

    chart.Series[0].ItemsSource = new List<DataPoint>();
    (chart.Series[0].ItemsSource as List<DataPoint>).Add(new DataPoint())
    //Profit
    
  • 0

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

    chart.Series.Clear(); 
    chart.Series[0].Items.Add(new DataPoint(1, 2));
    

相关问题