2015-11-06 40 views
0

我正在異步添加系列點,這就是爲什麼我失去標準的oxyplot縮放。我想在功能ZoomFunction()恢復它,但我怎麼能得到從PlotModel.Series最大和最小Y值PlotModel.Axes[1].Zoom()從PlotModel獲取系列

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

     } 
    } 
} 

回答

0

你試過Axes.Reset()?這將重置曲線的軸,並且Oxyplot將自動縮放,以便所有數據將再次顯示。

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

我希望這會幫助你!