0

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;

私が言ったように、初心者だけなので、おそらくいくつかの明らかな間違いがあります. それらを指摘して私を教育してください。

ありがとう

4

2 に答える 2

1

メソッド内で PlotModel を宣言しています...関数を離れると範囲外になります。したがって、あなたは何にも縛られていません。PlotModel はパブリックにアクセス可能であり、ViewModel/Main で宣言されている必要があります。

于 2015-02-20T14:27:14.597 に答える
0

私は OxyPlot を初めて使用します。私が知っていることから、 using を含める必要があるかもしれません

using OxyPlot.WPF;

宣言。

への呼び出しも

openPlot InvalidatePlot(true);

再描画をトリガーするために必要になる場合があります。

追加する必要があるかもしれません

openPlot.Series.Clear();

シリーズを追加する前に、それらのシリーズを再度追加する可能性がある場合。

于 2014-09-30T20:25:18.650 に答える