Quantcast
Channel: OxyPlot (moved to GitHub)
Viewing all articles
Browse latest Browse all 2061

Commented Unassigned: Plot not refreshing when bound in WPF [10191]

$
0
0
I'm asynchonrously getting data and attempting to populate a plot via the LineSeries, except the plot does not refresh when the bound collection (ObservableCollection) is updated.

__Can anyone explain why the plot is updating as expected?__

WPF
.Net 4.0
OxyPlot 2014.1.293.1

I have the following XAML datatemplate, as you can see the LineSeries ItemsSource is bound to a property (PlotData) in the ViewModel:

```
<DataTemplate DataType="{x:Type md:DataViewModel}">

<Grid>

<oxy:Plot x:Name="MarketDatePlot"
Margin="10">
<oxy:Plot.Axes>
<oxy:DateTimeAxis Position="Bottom"
StringFormat="dd/MM/yy"
MajorGridlineStyle="Solid"
MinorGridlineStyle="Dot"
IntervalType="Days"
IntervalLength="80"/>
<oxy:LinearAxis Position="Left"
MajorGridlineStyle="Solid"
MinorGridlineStyle="Dot"
IntervalLength="100"/>
</oxy:Plot.Axes>
<oxy:LineSeries ItemsSource="{Binding Path=PlotData, Mode=OneWay}" />
</oxy:Plot>
</Grid>

</DataTemplate>
```
The ViewModel is shown below:

```
public sealed class DataViewModel : BaseViewModel, IDataViewModel
{
private readonly CompositeDisposable _disposable;
private readonly CancellationTokenSource _cancellationTokenSource;
private readonly ObservableCollection<DataPoint> _plotData;

public DataViewModel(DateTime fromDate, DateTime toDate, IMarketDataService marketDataService, ISchedulerService schedulerService)
{
_plotData = new RangeObservableCollection<DataPoint>();
_disposable = new CompositeDisposable();

if (fromDate == toDate)
{
// nothing to do...
return;
}

_cancellationTokenSource = new CancellationTokenSource();

_disposable.Add(Disposable.Create(() =>
{
if (!_cancellationTokenSource.IsCancellationRequested)
{
_cancellationTokenSource.Cancel();
}
}));

marketDataService.GetDataAsync(fromDate, toDate)
.ContinueWith(t => t.Result.Select(x => new DataPoint(DateTimeAxis.ToDouble(x.Time), x.Value)), schedulerService.Task.Default)
.ContinueWith(t => _plotData.AddRange(t.Result), schedulerService.Task.CurrentSynchronizationContext);
}

public void Dispose()
{
_disposable.Dispose();
}

public IEnumerable<DataPoint> PlotData
{
get { return _plotData; }
}
}
```
Comments: I think this question should be posted under discussion. This library is not observing changes to the data - both for internal data structures (in PlotModel) and for bound data structures. This is the intended behavior and not a defect. I chose this design to keep the library simple. Remember that most properties and collections can possibly invalidate the whole view. But I have added a new workitem where you can vote if you want this feature! https://oxyplot.codeplex.com/workitem/10193

Viewing all articles
Browse latest Browse all 2061

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>