0

I am adding points to series asynchronously and that's why i am loosing standard oxyplot zooming. I want to restore it in function ZoomFunction() but how can i get Maximum and Minimum Y values from PlotModel.Series for PlotModel.Axes[1].Zoom()?

namespace WpfApplication2
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        public MainWindow()
        {
            InitializeComponent();
            DataContext = new Data();
        }
    }

    public class Data
    {
        public PlotModel PlotModel {get;set;}

        public Data()
        {
            PlotModel = new PlotModel();
            AddAxes(PlotModel);
            AddHistoryAsync(PlotModel);
        }

        public void AddHistoryAsync(PlotModel PlotModel)
        {
            Action<PlotModel> History = new Action<PlotModel>(AddHistory);
            IAsyncResult result = History.BeginInvoke(PlotModel, null, null);
        }

        public void AddAxes(PlotModel PlotModel)
        {
            var XAxis = new LinearAxis
            {
                Position = AxisPosition.Bottom
            };
            var YAxis = new LinearAxis
            {
                Position = AxisPosition.Left
            };
            PlotModel.Axes.Add(XAxis);
            PlotModel.Axes.Add(YAxis);
        }

        public void AddHistory(PlotModel PlotModel)
        {
            System.Threading.Thread.Sleep(3000);
            Random rnd = new Random();

            LineSeries LS = new LineSeries();
            for (int i = 0; i < 10; i++)
            {
                LS.Points.Add(new DataPoint(i, rnd.Next(1,100)));
            }
            PlotModel.Series.Add(LS);
            ZoomFunction(PlotModel);
            PlotModel.InvalidatePlot(false);
        }

        public void ZoomFunction(PlotModel PlotModel)
        {

        }
    }
}
Jose
  • 1,857
  • 1
  • 16
  • 34
A191919
  • 3,422
  • 7
  • 49
  • 93

1 Answers1

0

Did you try Axes.Reset()? This will reset the axes of the plot and Oxyplot will auto zoom so that all data will be shown again.

public void ZoomFunction(PlotModel PlotModel)
{
    foreach (var axes in PlotModel.Axes)
    {
        axes.Reset();
    }
    PlotModel.InvalidatePlot(true);
}

I hope this will help you!