6

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.

user1938742
  • 305
  • 1
  • 6
  • 18

2 Answers2

10

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.

Guillermo Ruffino
  • 2,940
  • 1
  • 26
  • 23
1

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.

JohnnyQ
  • 1,591
  • 1
  • 16
  • 25
  • I ended up creating a new PlotModel with my data since this required less code. I mark this as accepted, but I have a feeling that it must be an easier way. PlotView.Refresh() does not work either? – user1938742 Jun 26 '15 at 08:10