C # use Zedgraph to draw a detailed view of the histogram

Source: Internet
Author: User
1. Download Zedgraph control: http://download.csdn.net/detail/allisnew/322251

2. Add Reference ZedGraph.dll

3. Add a regular control on the last side of the toolbox--Browse--Select Zedgraph.dll

4. Write the following initialization code (you can also drag a control directly):

Private Zedgraphcontrol zedGraphControl1 = new Zedgraphcontrol (); This.zedGraphControl1.Location = new System.Drawing.Point (+/-);            This.zedGraphControl1.Name = "ZedGraphControl1";            This.zedGraphControl1.ScrollGrace = 0;            This.zedGraphControl1.ScrollMaxX = 0;            This.zedGraphControl1.ScrollMaxY = 0;            this.zedGraphControl1.ScrollMaxY2 = 0;            This.zedGraphControl1.ScrollMinX = 0;            This.zedGraphControl1.ScrollMinY = 0;            this.zedGraphControl1.ScrollMinY2 = 0;            This.zedGraphControl1.Size = new System.Drawing.Size (427, 247);            This.zedGraphControl1.TabIndex = 0;            This. Controls.Add (ZEDGRAPHCONTROL1);

5. Write the drawing code:

 private void Showchart () {zedGraphControl1.GraphPane.CurveList.Clear ();            ZedGraphControl1.GraphPane.GraphObjList.Clear ();            Clearing not teste graphpane mypane = Zedgraphcontrol1.graphpane;  MyPane.Title.Text = "Consumer education Statistics"; The title of the design chart MyPane.XAxis.Title.Text = "degree type"; X Axis Title MyPane.YAxis.Title.Text = "Number of people";            Y-Axis Title//MyPane.XAxis.Type = ZedGraph.AxisType.Date;            Date wont pointpairlist ppla = new Pointpairlist ();            Pointpairlist PPLB = new Pointpairlist ();            Pointpairlist PPLC = new Pointpairlist ();            Pointpairlist PPLD = new Pointpairlist ();                for (int i = 1; i < 2; i++) {Ppla.add (i, i + 3);                Pplb.add (i + 1, i + 4);                Pplc.add (i + 2, i + 5);            Ppld.add (i + 3, i + 6); }//Dragged drawing baritems out of Forloop BAritem Mybara = Mypane.addbar ("A", Ppla, color.red);            Baritem Mybarb = Mypane.addbar ("B", PPLB, Color.Blue);            Baritem Mybarc = Mypane.addbar ("C", PPLC, Color.gray);            Baritem Mybard = Mypane.addbar ("D", PPLD, Color.Black);            Zedgraphcontrol1.axischange (); Zedgraphcontrol1.refresh ();//This sentence is very important, otherwise it will not be displayed immediately}

If you want to display text in the horizontal axis:

 private void Showchart () {zedGraphControl1.GraphPane.CurveList.Clear ();            ZedGraphControl1.GraphPane.GraphObjList.Clear ();            Clearing not teste graphpane mypane = Zedgraphcontrol1.graphpane;            Drawing Panel Title MyPane.Title.Text = "Income statistics";            Drawing Panel x Title MyPane.XAxis.Title.Text = "Area";            myPane.XAxis.Scale.Min = 0;            Initialize data pointpairlist list = new Pointpairlist ();            Pointpairlist list2 = new Pointpairlist ();            Pointpairlist list3 = new Pointpairlist (); for (int i = 0; i < 5; i++)////The number here is consistent with lable, for example, the horizontal axis shows 5 lable, which will give 5 {list.                ADD (i, i+1); List2.                ADD (i, i + 2); List3.            ADD (i, i + 3);            }//Drawing panel y title MyPane.YAxis.Title.Text = "Sales";            column brushes//Public Baritem Addbar (string name, ipointlist data, color colors); Baritem Mycurve = Mypane.addbar ("Income 1", List, color.blue);            Baritem myCurve1 = Mypane.addbar ("Income 2", List2, Color.purple);            Baritem myCurve2 = Mypane.addbar ("Income 3", LIST3, Color.yellowgreen); MyCurve.Bar.Fill = new Fill (Color.Blue, Color.White, color.blue);//gradient//Baritem myCurve2 = Mypane.addbar ("Buy pesticide           ", List2, color.red);          MyCurve2.Bar.Fill = new Fill (color.red, Color.White, color.red);           Baritem myCurve3 = Mypane.addbar ("Buy fertilizer", List3, Color.green);            MyCurve3.Bar.Fill = new Fill (Color.green, Color.White, Color.green);            MyPane.XAxis.MajorTic.IsBetweenLabels = true;            Xaxis Callout string[] labels = {"Product 1", "Product 2", "Product 3", "Product 4", "Product 5"};            MyPane.XAxis.Scale.TextLabels = labels;            MyPane.XAxis.Type = Axistype.text;            Color outside the plot area//Mypane.fill = new Fill (Color.White, Color.FromArgb (255), 45.0f); Background color//MyPane.Chart.Fill = new Fill (COlor.            Red, Color.lightgoldenrodyellow, 45.0f);            Zedgraphcontrol1.axischange ();        Zedgraphcontrol1.refresh (); }

The above is C # use Zedgraph to draw the detailed content of the histogram, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.