Basic tutorial-Section 5 Introduction to barchartsampledemo. CS

Source: Internet
Author: User

Section 5 barchartsampledemo. CS Introduction Starting from this section, we will go to the research of bar chart (for example). First, we will start from the simplest barchartsampledemo and step by step into the bar world of zedgraph. The Code is as follows: using system; using system. drawing; using system. collections; using zedgraph; namespace zedgraph. demo {/// <summary> /// summary description for simpledemo. /// </Summary> public class barchartsampledemo: demobase {public barchartsampledemo (): Base ("Code project bar chart sample", "bar chart sample", demotype. tutorial) {graphpane mypane = base. graphpane; // set the titles and axis labels myp Ane. title = "my test bar graph"; mypane. xaxis. title = "label"; mypane. yaxis. title = "My Y axis"; // make up some random data points string [] labels = {"Panther", "lion", "Cheetah", "cougar ", "Tiger", "leopard"}; double [] Y = {100,115, 75, 22, 98, 40}; double [] y2 = {90,100, 95, 35, 80, 35}; double [] Y3 = {80,110, 65, 15, 54, 67}; double [] Y4 = {120,125,100, 40,105, 75}; // generate A red bar with "curve 1" in the legend baritem mybar = mypane. addbar ("curve 1", null, Y, color. red); mybar. bar. fill = New fill (color. red, color. white, color. red); // generate a blue bar with "curve 2" in the legend mybar = mypane. addbar ("curve 2", null, Y2, color. blue); mybar. bar. fill = New fill (color. blue, color. white, color. blue); // generate a green bar with "curve 3" in the legend myb AR = mypane. addbar ("curve 3", null, Y3, color. green); mybar. bar. fill = New fill (color. green, color. white, color. green); // generate a black line with "curve 4" in the legend lineitem mycurve = mypane. addcurve ("curve 4", null, Y4, color. black, symboltype. circle); mycurve. line. fill = New fill (color. white, color. lightskyblue,-45f); // fix up the curve attributes a little mycurve. symbol. size = 8.0f; mycurve. symbol. fill = New fill (color. white); mycurve. line. width = 2.0f; // draw the X tics between the labels instead of at the labels mypane. xaxis. isticsbetweenlabels = true; // set the xaxis labels mypane. xaxis. textlabels = labels; // set the xaxis to text type mypane. xaxis. type = axistype. text; // fill the axis area with a gradient mypane. axisfill = New fill (color. white, color. fromar GB (255,255,166), 90f); // fill the pane area with a solid color mypane. panefill = New fill (color. fromargb (250,250,255); base. zedgraphcontrol. in the axischange () ;}} section, we mainly introduce the baritem class, which is the column Class in zedgraph. Its Inheritance relationship is as follows: system. Object
Zedgraph. curveitem Zedgraph. baritemIts base class zedgraph. curveitem contains the data and methods of a single curve chart on pane. It sets chart attributes, such as keywords (KEYS), member names, colors, symbols, sizes, and line styles. There are five constructors in baritem, two of which are commonly used, as follows: // create a new baritem, specifying only the legend label for the bar. public baritem (string); // create a new baritem using the specified properties. public baritem (string, double [], double [], color); baritem mybar = mypane. addbar ("curve 1", null, Y, color. red); mybar. bar. fill = New fill (color. red, color. white, color. red); here we use addbar in pane to set the column and return a reference to the baritem. To further describe this bar. We can see that "curve1" in the constructor is the text to be displayed in legend (for details about legend, refer to section 1 ). The Axis label on the X axis is not set first, followed by the Y axis and the bar color. The second line of code uses the reference mybar to fill the bar with red-white-red colors. // Draw the X tics between the labels instead of at the labelsmypane. xaxis. isticsbetweenlabels = true; // set the xaxis labelsmypane. xaxis. textlabels = labels; // set the xaxis to text typemypane. xaxis. type = axistype. text; the first line of code is mainly to set the position of the column on the X axis, which is centered by default. If this item is not set, or set this item to false, the bar is centered on the interface, for example: (mypane. xaxis. isticsbetweenlabels = false;) the second and third lines of code indicate that the coordinates of the X axis are displayed in text format. The text content is from string [] labels. // Fill the axis area with a gradientmypane. axisfill = New fill (color. white, color. fromargb (255,255,166), 90f); // fill the pane area with a solid colormypane. panefill = New fill (color. fromargb (250,250,255); one of the last two sentences is to set the background color of the pane axis, with a gradient effect from white to pale yellow at a 90 degree angle; the other is to set the background color of pane, it is light gray and white, which is not obvious in the figure. Please change it to color by yourself. fromargb (250,250, 0. The fully-filled graph has been introduced in sections 1, 2, 3, and 4. It is no longer repeated here. Please refer to the previous sections.

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.