3

私のプロジェクトでは、デュアル Y 軸グラフにリアルタイム データを追加して更新する必要があります。Y 値と Y2 値は同じ X 値を共有しており、既に作成しています。これで、新しいポイント ペアを曲線リストに追加する関数ができました。

これが私の問題です。私の Y 値と Y2 値は常に最初の曲線の曲線リストに追加されます。Y2 値をグラフの 2 番目の曲線リストに追加するにはどうすればよいですか?

ここに私の関数コードがあります:

    private void AddDataToGraph(ZedGraphControl zg1, XDate xValue, double yValue1, double yValue2)
    {
        // Make sure that the curvelist has at least one curve.
        if (zg1.GraphPane.CurveList.Count <= 0)
            return;

        // Get the first CurveItem in the graph.
        LineItem curve = zg1.GraphPane.CurveList[0] as LineItem;

        if (curve == null)
            return;

        // Get the PointPairList.
        IPointListEdit list = curve.Points as IPointListEdit;
        IPointListEdit list2 = curve.Points as IPointListEdit;

        // If this is null, it means the reference at curve.Points does not
        // support IPointListEdit, so we won't be able to modify it.
        if (list == null || list2 == null)
            return;

        // Add new data points to the graph.
        list.Add(xValue, yValue1);
        list2.Add(xValue, yValue2);

        // Force redraw.
        zg1.Invalidate();
    }

Y2 値を 2 番目の曲線リストに追加するにはどうすればよいですか?

4

2 に答える 2

9

自分で可能な解決策を見つけました。ここに私のコードの変更があります:

private void AddDataToGraph(ZedGraphControl zg1, XDate xValue, double yValue1, double yValue2)
    {
        // Make sure that the curvelist has at least one curve
        if (zg1.GraphPane.CurveList.Count <= 0)
            return;

        // Get the first CurveItem in the graph
        LineItem curve = zg1.GraphPane.CurveList[0] as LineItem;
        LineItem curve2 = zg1.GraphPane.CurveList[1] as LineItem;

        if (curve == null || curve2 == null)
            return;

        // Get the PointPairList
        IPointListEdit list = curve.Points as IPointListEdit;
        IPointListEdit list2 = curve2.Points as IPointListEdit;
        // If this is null, it means the reference at curve.Points does not
        // support IPointListEdit, so we won't be able to modify it
        if (list == null || list2 == null)
            return;

        // add new data points to the graph
        list.Add(xValue, yValue1);
        list2.Add(xValue, yValue2);

        // force redraw
        zg1.Invalidate();
    }

重要なことは、「CurveList[i]」でインデックスを使用することです。したがって、[0] は Y 値の曲線で、[1] は Y2 値の曲線です。

これが同じまたは同様の問題を抱えている人の助けになることを願っています。

于 2010-08-13T19:52:31.783 に答える
1

上記の「より良い」実装は次のとおりです。

    private void AddDataToGraph(ZedGraphControl zg1, XDate xValue, double[] yValues)
    {
        GraphPane myPane = zg1.GraphPane;
        // Make sure that the curvelist has at least one curve
        if (myPane.CurveList.Count <= 0)
            return;
        else if (myPane.CurveList.Count != yValues.Length)
            return;

        for (int i = 0; i < yValues.Length; i++ )
        {
            ((IPointListEdit)myPane.CurveList[i].Points).Add(xValue, yValues[i]);
        }
        // force redraw
        zg1.Invalidate();
    }
于 2011-08-24T21:23:45.543 に答える