首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >OxyPlot WPF ViewMaximum

OxyPlot WPF ViewMaximum
EN

Stack Overflow用户
提问于 2015-04-15 09:15:38
回答 1查看 2.7K关注 0票数 1

在panning.Because之后,我试图在y轴上找到视图的最大值和最小值,我想放大屏幕。

代码

代码语言:javascript
运行
复制
using GalaSoft.MvvmLight.Command;
using OxyPlot;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication15
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
/// 
public class DataLoading
{
    public PlotModel PlotModel { get; set; }
    public ICommand TestCommand { get; set; }
    OxyPlot.Axes.LinearAxis X;
    OxyPlot.Axes.LinearAxis Y;
    private OxyPlot.Series.LineSeries FirstSeries;
    private OxyPlot.Series.LineSeries SecondSeries;
    private int i =0;
    public DataLoading()
    {
        TestCommand = new RelayCommand(()=>ShowActualPoints());
        PlotModel = new PlotModel();
        X = new OxyPlot.Axes.LinearAxis()
        {
            Position = OxyPlot.Axes.AxisPosition.Bottom,
            Minimum=1,
            Maximum=5
        };
        Y = new OxyPlot.Axes.LinearAxis()
        {
            Position = OxyPlot.Axes.AxisPosition.Left,
            IsPanEnabled = false
        };
        FirstSeries = new OxyPlot.Series.LineSeries();
        SecondSeries = new OxyPlot.Series.LineSeries();
        FirstLoad();

        PlotModel.Axes.Add(X);
        PlotModel.Axes.Add(Y);
        OxyPlot.Wpf.PlotView PV = new OxyPlot.Wpf.PlotView();
        PlotModel.Axes[0].AxisChanged += (o, e) =>
        {
            double LastPoint = (from y in FirstSeries.Points select y.X).Min();
            ShowActuals(LastPoint);
        };
    }
    public delegate void BeginUpdate();
    public void ShowActuals(double inputlastpoint)
    {

        if (inputlastpoint > PlotModel.Axes[0].ActualMinimum)
        {
            Debug.WriteLine("Need to load points");
            BeginUpdate BU = new BeginUpdate(SecondLoad);
            IAsyncResult result = BU.BeginInvoke(null,null);
        }
        else
        {
            Debug.WriteLine("No need to load points");
        }
    }

    private void FirstLoad()
    {
        FirstSeries.Points.Add(new DataPoint(1, 1));
        FirstSeries.Points.Add(new DataPoint(2, 2));
        FirstSeries.Points.Add(new DataPoint(3, 3));
        FirstSeries.Points.Add(new DataPoint(4, 3));
        FirstSeries.Points.Add(new DataPoint(5, 3));
        PlotModel.Series.Add(FirstSeries);
    }
    private void SecondLoad()
    {
        Random rnd = new Random();
        FirstSeries.Points.Insert(0,new DataPoint(--i, rnd.NextDouble()));
        System.Threading.Thread.Sleep(1000);
        PlotModel.InvalidatePlot(true);
    }
    private void ShowActualPoints()
    {
        Debug.WriteLine("Y:{0}",PlotModel.Axes[1].ActualMaximum);
        Debug.WriteLine("X:{0}", PlotModel.Axes[0].ActualMaximum);
        //Debug.WriteLine("Y:{0}", PlotModel.Axes[1].Act);
        //Debug.WriteLine("X:{0}", PlotModel.Axes[0].ActualMaximum);
        //Debug.WriteLine(PlotModel.Series[0].GetNearestPoint(new ScreenPoint(PlotModel.Axes[0].ActualMaximum, PlotModel.Axes[1].ActualMaximum), false));
    }
}
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        DataContext= new DataLoading();
    }
}

}

Y轴具有一定的性质ViewMaximum和ViewMinimum.但它们都是空的。**

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-05 08:43:27

在创建Y轴之前获取数据。这将允许您找到最小和最大y值,然后设置y轴的最小值和最大值。

要获得最小和最大点,您可以根据它们的Y值对它们进行排序,然后取第一点和最后一点。

代码语言:javascript
运行
复制
var orderedSeries = yourDataSeries.OrderBy(o => o.YValue).ToList();

int lowestPoint = orderedSeries.First.YValue;
int highestPoint = orderedSeries.Last.YValue;

Y = new OxyPlot.Axes.LinearAxis()
{
    Minimum = lowestPoint,
    Maximum = highestPoint,
    Position = OxyPlot.Axes.AxisPosition.Left,
    IsPanEnabled = false
};

你应该看一些非常类似的东西。

希望这能有所帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29646257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档