【问题标题】:Struggling with OxyPlot与 OxyPlot 斗争
【发布时间】:2015-02-20 22:27:14
【问题描述】:

现在已经学习 C# 和 WPF 大约 5 或 6 周了,我正在一个项目中担任实习生。没有做坏事,但现在我被卡住了,我不知道为什么。尝试将 WinForms 应用程序迁移到 WPF。旧应用程序使用 Z 图,为 OxyPlot 编写了代码,但我的图没有显示,我不知道为什么。

XAML

<Border BorderBrush="{StaticResource chromeBrush}" BorderThickness="5 5 5 5" Margin="2 3 0 2" Grid.Column="3" Grid.ColumnSpan="36" Grid.Row="3" Grid.RowSpan="33" Background="Black"> <DockPanel> <DockPanel.DataContext> <local:Main/> </DockPanel.DataContext> <oxy:Plot Model="{Binding openPlot}" /> </DockPanel> </Border>

还有 C#

public partial class Main : Window
{

    public Dictionary<string, DoorData> doorList;

    public Main()
    {
        //this.InitializeComponent();
        doorList = new Dictionary<string, DoorData>();

    }

    public DoorData doorGraphs = new DoorData();

    private void unitList_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        string selectedUnit = unitList.SelectedItem.ToString();
        doorGraphs = doorList[selectedUnit];

        this.Title = selectedUnit + " Open";
        PlotModel openPlot = new PlotModel();

        List<SmartDDUOperation> values = doorGraphs.Data;
        doorGraphs.FilterToType(SmartOperationType.Open);
        IEnumerable<SmartDDUOperation> drawOrder = values.OrderByDescending(x => x.TimeStamp);

        List<LineSeries> linePointsArray = new List<LineSeries>();
        foreach (SmartDDUOperation doorOp in drawOrder)
        {
            List<Tuple<double, double>> points = new List<Tuple<double, double>>();
            points = doorOp.GetTimePoints2();
            LineSeries linePoints = new LineSeries();

            foreach (Tuple<double, double> p in points)
            {
                DataPoint XYPoint = new DataPoint(p.Item1, p.Item2);
                linePoints.Points.Add(XYPoint);
            }

            linePointsArray.Add(linePoints);
        }

        LinearAxis Xaxis = new LinearAxis();
        Xaxis.Maximum = 6;
        Xaxis.Minimum = 0;
        Xaxis.Position = AxisPosition.Bottom;
        Xaxis.Title = "Time (s)";
        openPlot.Axes.Add(Xaxis);

        LinearAxis Yaxis = new LinearAxis();
        Yaxis.Maximum = 12;
        Yaxis.Minimum = 1;
        Yaxis.Position = AxisPosition.Left;
        Yaxis.Title = "Door Position";
        openPlot.Axes.Add(Yaxis);

        // Adds each series to the graph

        foreach (var series in linePointsArray)
        {
            openPlot.Series.Add(series);
        }



    }

使用以下命名空间...

enter using OxyPlot; using OxyPlot.Annotations; using OxyPlot.Series; using OxyPlot.Axes;

就像我说的,只是一个初学者,所以那里可能有一些明显的错误。随时指出并教育我。

谢谢

【问题讨论】:

    标签: oxyplot


    【解决方案1】:

    您在方法内声明您的 PlotModel...当您离开该函数时,它将超出范围。所以你对任何东西都没有约束力。您的 PlotModel 需要可公开访问并在您的 ViewModel/Main 中声明。

    【讨论】:

      【解决方案2】:

      我自己是 OxyPlot 的新手。据我所知,您可能需要包含一个 using

      using OxyPlot.WPF;
      

      声明。

      也是对

      的调用
      openPlot InvalidatePlot(true);
      

      可能需要触发重绘。

      您可能需要添加一个

      openPlot.Series.Clear();
      

      在添加系列之前,如果有任何方法可以再次添加这些系列。

      【讨论】:

        猜你喜欢
        • 2020-09-18
        • 2018-05-23
        • 2013-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-30
        • 2014-10-04
        • 2019-08-10
        相关资源
        最近更新 更多