简体   繁体   中英

OxyPlot InvalidatePlot not refreshing data

I'm trying to dynamically add points to a LineSeries , but it doesn't show up after invalidating the plot. Using newest OxyPlot version 2014.1.301.1, straight from NuGet. It works if I set the ItemSource to a new list, but editing the Items property does nothing.

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>

Code:

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

Ignore the Items property and work only with the ItemSource , it then works like a charm.

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

I haven't been able to work chart.InvalidatePlot(true); but chart.Series.Clear(); has worked well. I would try placing it before your new data points with something like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM