1

我对这个问题感到困惑:我有一个带有 ZedGraph 对象的 WinForm 绘制一条简单的曲线。它在每个点上方都有一个自定义文本对象“C”。当我将 XAxis.Type 更改为 DateAsOrdinal 时,“C”文本标签消失了。如何使用 DateAsOrdinal 获得“C”?

代码如下,任何人都可以尝试:

    private void DrawChart( ZedGraphControl zGraph ) {
        GraphPane pane = zGraph.GraphPane;
        pane.Title.Text = "My Sample Test";
        pane.XAxis.Title.Text = "Date";
        pane.YAxis.Title.Text = "Price";

        // Uncomment below line: all "C" labels disappear!
        //pane.XAxis.Type = AxisType.DateAsOrdinal;

        double x, y;
        PointPairList points = new PointPairList();
        DateTime day = new DateTime( 2012, 1, 1 );

        for ( int i = 0 ; i < 36 ; i++ ) {
            x = day.ToOADate();
            y = 1.5 + Math.Sin( (double)i * 0.2 );
            points.Add( x, y );

            // this label disappears when XAxis.Type = DateAsOrdinal!
            TextObj text = new TextObj( "C", x, y + 0.1, CoordType.AxisXYScale, AlignH.Center, AlignV.Center );
            text.ZOrder = ZOrder.A_InFront;
            text.FontSpec.Border.IsVisible = false;
            pane.GraphObjList.Add( text );

            day = day.AddDays( 1 );   // goto next day (x-coord)
        }

        LineItem curve = pane.AddCurve( "Stock", points, Color.Black, SymbolType.None );

        zGraph.AxisChange();
    }
4

1 回答 1

1

尝试

新的 TextObj("C", i + 1, y + .....

Ordinal XAxis 表示表达式意味着 x 值将运行 1、2、3...

于 2013-01-23T11:32:03.923 回答