How can I make OxyPlot adjust zoom when calling PlotView.Invalidate?

7k views Asked by At

I have a problem with OxyPlot which is as follows:

I create a new PlotView and attach a PlotModel with some axes when my program starts.

In my program, the user can open a file, which is interpreted and plotted in the PlotView control.

To display the new Series, I do

myPlotView.Invalidate(true);

This will display the data on in the plot, however OxyPlot does not perform any zooming. How can I pan and zoom automatically, such that the plot covers the whole PlotView?

I tried to set

 myPlotView.Model.Axes[0].DataMinimum = someValue1
    myPlotView.Model.Axes[1].DataMinimum = someValue2
    myPlotView.Model.Axes[0].DataMaximum = someValue3
    myPlotView.Model.Axes[1].DataMaximum = someValue4

but nothing happens.

2

There are 2 answers

0
Guillermo Ruffino On BEST ANSWER

Axes calculates the ViewMinimum and ViewMaxium (the real thing you are watching) only if Minimum and Maximum are not specified, you can set them to Double.NaN before resetting, so the ViewMinimum and ViewMaximum will be calculated based on DataMinimum and DataMaximum

foreach (var ax in _plotModel.Axes)
    ax.Maximum = ax.Minimum = Double.NaN;
PlotView.ResetAllAxes(); 

Also if you changed the data points, you must call to Plot.InvalidatePlot() so the DataMinimum and DataMaximum gets updated too.

1
JohnnyQ On

Do a Axis reset and update the Minimum/Maximum of each Axis.

e.g.

      PlotView.ActualModel.Axes[0].Reset();
      PlotView.ActualModel.Axes[1].Reset();

      PlotView.ActualModel.Axes[0].Minimum = 50;
      PlotView.ActualModel.Axes[0].Maximum = 250;

      PlotView.ActualModel.Axes[1].Minimum = 50;
      PlotView.ActualModel.Axes[1].Maximum = 250;
      PlotView.InvalidatePlot(true);

you should of course use the min/max value from your data.