我正在异步地向系列添加点数,这就是我失去标准的氧气图缩放的原因。我想在函数ZoomFunction()
中恢复它但是如何从PlotModel.Series
获取PlotModel.Axes[1].Zoom()
的最大和最小Y值?
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 :(得分:0)
你试过Axes.Reset()
吗?这将重置绘图的轴,Oxyplot将自动缩放,以便再次显示所有数据。
public void ZoomFunction(PlotModel PlotModel)
{
foreach (var axes in PlotModel.Axes)
{
axes.Reset();
}
PlotModel.InvalidatePlot(true);
}
我希望这会对你有所帮助!