zedgraph折線圖點上數值顯示

來源:互聯網
上載者:User

 

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();
        }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.