How to update a function plot?

Aug 21, 2012 at 1:52 PM

Hi,

I would like to create plot, which relys on a function rather than on data points. This plot should automatically be updated in case of a change of the x axis. For instance, this should be done when a user zooms out (or in).

Manually, I have done this with text boxes, where you type in xmin and xmax and the graph is updated via data binding. Maybe, it is possible to extend this idea by binding to the minimum and maximum of the x axis. But I don't know how to do this. Has anyone an idea how to tackle this problem?

Coordinator
Aug 21, 2012 at 2:46 PM

Subscribe to the AxisChanged event on the axis. The ActualMaximum and ActualMinimum values are updated before the event is raised, and these values can be used to update the limits of your function series. Then call PlotModel.Refresh(true) (since the plot data was modified) to update the plot. 

Aug 22, 2012 at 8:17 AM

Thank you, for your immediate response. I thnk, your solution works fine in case of a pure C# program. But what I like to have is a C#/WPF solution with MVVM pattern. That is, I have

1.) a model for the function f(x). The evaluation of this function yiels the Points and depends on the limits of x: XMin, XMax.

       public double XMin { get; set; }

       public double XMax { get; set; }

       public IList<DataPoint> Points{  get  {  return evaluatedPoints;  }  }

2.) a view model where OnPropertyChanged of the Points and the changed limit is raised.

       public IList<DataPoint> Points { get { return model.Points; } }

       public double XMax // same for XMin

       {

           get { return model.XMax; }

           set

           {

               model.XMax = value;

               OnPropertyChanged("XMax");

               OnPropertyChanged("Points");

          }

       }

3.) a WPF view where the axis properties are modified. With respect to XMax we have for instance

           <oxy:Plot.Axes>

               <oxy:LinearAxis Position="Bottom">

                   <oxy:LinearAxis.Maximum>

                       <Binding Mode="TwoWay"

                               Path="XMax"

                               Source="{StaticResource viewModel}"

                               UpdateSourceTrigger="PropertyChanged" />

                   </oxy:LinearAxis.Maximum>

               </oxy:LinearAxis>

           <oxy:Plot.Axes/>

 

The problem is that there is no dependency property for ActualMaximum and ActualMinimum. Of course, I could implement this. But I don't like this approach, because than I am modifying your library. As a consequence I have to do this modification for all future versions.

To this end, I would like to ask you, if you can do this?


Coordinator
Aug 24, 2012 at 8:12 AM

I think it could be possible to add an AxisChanged routed event on the OxyPlot.Wpf.LinearAxis. This could pass the events from the OxyPlot.LinearAxis. http://oxyplot.codeplex.com/workitem/9992

It should also be possible to make some read-only dependency properties for ActualMaximum/ActualMinimum, which may get change notifications every time the plot is changed (e.g. panned, zoomed or data changed). http://oxyplot.codeplex.com/workitem/9993

Aug 24, 2012 at 10:00 AM

Hi objo, that would be cool! I am looking forward to this feature!