Winform "zedgraph Bar Chart" control development of catering system based on experience sharing

Source: Internet
Author: User

This article is mainly to share with you the use of the "zedgraph Bar Chart" Control in the new module development of the catering system. Let's take a look at the effects I have applied in the project:

As shown in, this bar chart only has the Y axis, and the color of each column is different-NO x axis, but the name and score of each constitution need to be displayed, which needs to be in the regular (online example) and then make modifications.

KeyCodeAs follows:

   Void  Showbar (  Double  [] Tzzhfarr)
{
String [] Tztypearr = Comhelper. gettztypearray ();
Dictionary < Int , Double [] > Dict = New Dictionary < Int , Double [] > ();
Color [] colorarr = {Color. Orange, color. palegreen, color. slateblue,
Color. Pink, color. Green, color. lightskyblue,
Color. Gray, color. greenyellow, color. rosybrown };

This . Zedgraphcontrol_res.suspendlayout ();

This . Zedgraphcontrol_res.controls.clear ();
Zedgraph. graphpane mypane = This . Zedgraphcontrol_res.graphpane;

Mypane. Title. Text = " Bar Chart of Physical Fitness Test Results " ;
Mypane. xaxis. Title. Text = "" ;
Mypane. yaxis. Title. Text = "" ;

Int Start_x = 5 ;
Double Tzzhz = 0 ;
For ( Int I = 0 ; I < Tztypearr. length; I ++ )
{
Tzzhz = Tzzhfarr [I] < 0 ? 0 : Tzzhfarr [I];
Zedgraph. baritem bar = Mypane. addbar ( "" , New Double [] {Start_x }, New Double [] {Tzzhz}, colorarr [I]);
Bar. Bar. Fill = New Zedgraph. Fill (colorarr [I], color. White, colorarr [I]);

Zedgraph. textobj mytext = New Zedgraph. textobj ( String . Format ( " {0}, {1} " , Tztypearr [I], tzzhz), start_x, tzzhz + 3 );
Mytext. Location. coordinateframe = Zedgraph. coordtype. axisxyscale;
Mytext. Location. alignh = Zedgraph. alignh. Center;
Mytext. Location. alignv = Zedgraph. alignv. Center;
Mytext. fontspec. Family = " " ;
Mytext. fontspec. Size = 16f;
Mytext. fontspec. Fill. isvisible = False ;
Mytext. fontspec. Border. isvisible = False ;
// Mytext. fontspec. angle = 35; // Control text skew
Mypane. graphobjlist. Add (mytext );
Start_x + = 15 ;
}

Mypane. Fill = New Zedgraph. Fill (color. whitesmoke, color. Lavender, 0f );
Mypane. Chart. Fill = New Zedgraph. Fill (color. fromargb ( 255 , 255 , 245 ),
Color. fromargb ( 255 , 255 , 190 ), 90f );
// Set the width of the bar
Mypane. barsettings. clusterscalewidth = 30 ;
// Bars are stacked
Mypane. barsettings. Type = Zedgraph. bartype. cluster;

Mypane. xaxis. isvisible = False ;

// Enable the X and Y Axis Grids
Mypane. xaxis. majorgrid. isvisible = False ;
Mypane. yaxis. majorgrid. isvisible = True ;


Mypane. xaxis. Scale. Min = - 10 ;
This . Zedgraphcontrol_res.resumelayout ();
This . Zedgraphcontrol_res.axischange ();
}

There are several important attributes that need special instructions:

1. // set the width of the bar
Mypane. barsettings. clusterscalewidth = 30;
// Bars are stacked
Mypane. barsettings. type = zedgraph. bartype. cluster;

Setting the width of a bar is only valid for some values in mypane. barsettings. Type (Bar layout setting or type.

2. mytext. fontspec. angle = 35; // control the text skew

3. When mypane. xaxis. isvisible = false, the text below the X axis (usually the value of-y) cannot be displayed.

-- Zedgraph is a foreign control with powerful functions. It may be more convenient or appropriate for me to achieve the effect. I also have a rough understanding of it, hope that our friends will share your experience!

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.