zedgraph折线图点上数值显示

 如图

private void Form4_Load(object sender, EventArgs e)
        {
            CreateChart(zedGraphControl1);
        }

public void CreateChart(ZedGraphControl zgc)
        {
            GraphPane myPane = zgc.GraphPane;

            // Set the titles and axis labels
            myPane.Title.Text = "生产线产量分析图";
            //myPane.XAxis.Title.Text = "时间段";
            //myPane.YAxis.Title.Text = "Pressure, Psia";
            myPane.XAxis.Title.IsVisible = false;
            myPane.YAxis.Title.IsVisible = false;
            myPane.XAxis.MajorGrid.IsVisible = true;  //珊格子
            myPane.YAxis.MajorGrid.IsVisible = true;
            string[] labels = { "7~8点", "8~9点", "9~10点", "10~11点", "11~12点", "12~13点", "13~14点","14~15点" ,"15~16点","16~17点","17~18点"};
            double[] y = { 2000, 1000, 5000, 2500, 3500, 7500,4000,5200};
            double[] x = { 4000, 3000, 2500, 3500, 1500, 5500, 2000};
            // Hide the legend
            myPane.Legend.IsVisible = true;

            // Add a curve
            LineItem curve = myPane.AddCurve("总产量", null,y, Color.Red, SymbolType.Diamond);
            curve.Line.Width = 2.0F;
            curve.Line.IsAntiAlias = true;
            curve.Symbol.Fill = new Fill(Color.White);
            curve.Symbol.Size = 7;
            LineItem curve1 = myPane.AddCurve("C线产量", null, x, Color.Blue, SymbolType.Circle);
            curve1.Line.Width = 2.0F;
            curve1.Line.IsAntiAlias = true;
            curve1.Symbol.Fill = new Fill(Color.White);
            curve1.Symbol.Size = 7;
            // Fill the axis background with a gradient
            myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, Color.ForestGreen), 45.0F);

            // Offset Y space between point and label
            // NOTE:  This offset is in Y scale units, so it depends on your actual data
            const double offset = 1.0;

            // Loop to add text labels to the points
            for (int i = 0; i < y.Length; i++)
            {
                // Get the pointpair
                PointPair pt = curve.Points[i];

                // Create a text label from the Y data value
                TextObj text = new TextObj(pt.Y.ToString("f2"), pt.X, pt.Y + offset,
                    CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
                text.ZOrder = ZOrder.A_InFront;
                // Hide the border and the fill
                text.FontSpec.Border.IsVisible = false;
                text.FontSpec.Fill.IsVisible = false;
                //text.FontSpec.Fill = new Fill( Color.FromArgb( 100, Color.White ) );
                // Rotate the text to 90 degrees
                text.FontSpec.Angle = 50;  //字体倾斜度
                myPane.GraphObjList.Add(text);
            }
            for (int i = 0; i < x.Length; i++)
            {
                // Get the pointpair
                PointPair pt = curve1.Points[i];

                // Create a text label from the Y data value
                TextObj text = new TextObj(pt.Y.ToString("f2"), pt.X, pt.Y + offset,
                    CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
                text.ZOrder = ZOrder.A_InFront;
                // Hide the border and the fill
                text.FontSpec.Border.IsVisible = false;
                text.FontSpec.Fill.IsVisible = false;
                //text.FontSpec.Fill = new Fill( Color.FromArgb( 100, Color.White ) );
                // Rotate the text to 90 degrees
                text.FontSpec.Angle = 50;  //数值字体倾斜度
                myPane.GraphObjList.Add(text);
            }
            // Leave some extra space on top for the labels to fit within the chart rect
            //myPane.YAxis.Scale.MaxGrace = 0.2;
            
            myPane.XAxis.Type = AxisType.Text;
            myPane.XAxis.Scale.TextLabels = labels;
            myPane.XAxis.Scale.FontSpec.Size = 8; //x线字体
            myPane.XAxis.Scale.FontSpec.Angle = 60;//x线字体倾斜度
            // Calculate the Axis Scale Ranges
            zgc.AxisChange();
        }

转自:https://www.cnblogs.com/xiongeee/articles/953972.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值