How to update a function plot?

Oystein Bjorke 6 years ago 0
This discussion was imported from CodePlex

aec wrote at 2012-08-21 14:52:


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?

objo wrote at 2012-08-21 15:46:

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. 

aec wrote at 2012-08-22 09:17:

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; }



               model.XMax = value;





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


               <oxy:LinearAxis Position="Bottom">


                       <Binding Mode="TwoWay"


                               Source="{StaticResource viewModel}"

                               UpdateSourceTrigger="PropertyChanged" />





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?

objo wrote at 2012-08-24 09:12:

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.

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).

aec wrote at 2012-08-24 11:00:

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