4

I'm trying to use OxyPlot to visualize a time series and I'm using annontations to mark some points in time and value levels like minimum/maximum value and so on.

I want to achieve this in WPF with bindings and, so far, I started with the Plot control, two axes and a data series. This works fine, but I can't find a way to bind the annotations to an ObservableCollection<Annontation> with dynamically created annotations of all kinds.

<UserControl
    ...
    xmlns:oxy="http://oxyplot.org/wpf"
    ...
    >
    <Grid>
        ...
        <oxy:Plot>
            <oxy:Plot.Axes>
                <oxy:DateTimeAxis ... />
                <oxy:LinearAxis ... />
            </oxy:Plot.Axes>
            <oxy:Plot.Series>
                <oxy:StairStepSeries ... />
            </oxy:Plot.Series>
            <oxy:Plot.Annotations>
                <!--
                How do I bind to the ObservableCollection 'Annotations' in my ViewModel?
                Note, 'Annotations' property isn't available directly in Plot, either.
                -->
            </oxy:Plot.Annotations>
        </oxy:Plot>
    </Grid>
</UserControl>
Chris Tophski
  • 930
  • 1
  • 6
  • 23

2 Answers2

2

I run in a similar question. Just to provide an answer for others, how to handle this with OxyPlot:

If you have an unknown number of Annotations or Series, you should use

 <oxy:PlotView Model="{Binding PlotModel}" />

in Xaml and this Property on your ViewModel

public PlotModel PlotModel { get; set; }

On this property you have more flexibility. You can not set PlotModel.Annotations, like the LineSeries.ItemSource, but you can add and remove everey time so much annotations how you need.

RCP161
  • 199
  • 1
  • 13
  • Sounds great, however unfortunately I'm not using OxyPlot any more. But for curiosity, I'll try it later. Thanks :) – Chris Tophski Sep 23 '20 at 23:00
  • The code-behind plotmodel is the right way. I have experimented with both variants (OxyPlot+MVVM and bindings vs code-behind plotmodel) for years and the MVVM way is very limited. – Patrick Stalph Aug 10 '21 at 05:48
1

After nearly a year without an answer I decided to answer with a short roundup of my experience from trial-and-error during that time.

I basically gave up the approach with OxyPlot in my WPF-application, so if the reader is rather interested in a solution with OxyPlot, (s)he will probably not find an answer, here, sorry.

After googling and the already mentioned trial-and-error etc. I finally switched to a solution with a web based visualization (Grafana in my case) and a time series database (InfluxDB in my case). There are other possibilities for visualization and data sources etc., but for my case this was the most appropriate. I won't provide a comprehensive list, so please google for alternatives for this.

The most interesting thing for my .Net-case was that I could embed a part of my Grafana graphs in a web component on my WPF window, but I didn't end up using this solution, so I unfortunately can't give a comprehensive solution any more. The important thing was, I could use Grafana in .Net via web-stuff, so no further limitation.

Meanwhile I dived more into the systems mentioned above and could build some very useful dashboards for our case and very quickly build some interesting queries etc.. Even if you want to create your own visualization, I would recommend to set up a virtual machine with a visualization platform, a time series database (or any other database system) and some services/daemons/scripts running somewhere. That helped me a lot.

If someone likes to add something, please feel free. At least for my case this question is answered, so I'll close it.

Chris Tophski
  • 930
  • 1
  • 6
  • 23