Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

oxyplot

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.

like image 559
user1938742 Avatar asked Jun 25 '15 12:06

user1938742


2 Answers

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.

like image 81
Guillermo Ruffino Avatar answered Nov 11 '22 06:11

Guillermo Ruffino


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.

like image 32
JohnnyQ Avatar answered Nov 11 '22 05:11

JohnnyQ