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!