µ±Ç°Î»ÖãºÊ×Ò³ > ZedGraph¿Ø¼þÊôÐÔ¼°»ù´¡½Ì³ÌÏê½â(2003)
ZedGraph ÊôÐÔ¼°»ù´¡½Ì³Ì
myBar.Bar.Fill = new Fill( Color.Green, Color.White, Color.Green ); // Generate a black line with \4\in the legend
LineItem myCurve = myPane.AddCurve( \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.FromArgb( 255, 255, 166), 90F ); // Fill the pane area with a solid color
myPane.PaneFill = new Fill( Color.FromArgb( 250, 250, 255) ); base.ZedGraphControl.AxisChange(); } }
}
ÕâÒ»½Ú£¬ÎÒÃÇÖ÷Òª½éÉÜBarItemÕâ¸öÀ࣬Õâ¸öÀà¾ÍÊÇZedGraphÖйØÓÚÖùÐεÄÀà¡£ËüµÄ¼Ì³Ð¹ØÏµÈçÏ£º System.Object
ZedGraph.CurveItem ZedGraph.BarItem
ËüµÄ»ùÀàZedGraph.CurveItemÀï°üº¬ÁËPaneÉϵ¥¸öÇúÏßͼ±íµÄÊý¾ÝºÍ·½·¨¡£ËüʵÏÖÁËͼ±íµÄÊôÐÔÉèÖã¬ÀýÈç¹Ø¼ü´Ê(Key)£¬³ÉÔ±µÄÃû×Ö¡¢ÑÕÉ«¡¢·ûºÅ¡¢³ß´çºÍÏßÌõµÄ·ç¸ñµÈµÈ¡£
BarItemÖÐÓÐÎå¸ö¹¹Ô캯Êý£¬ÆäÖÐÓÐÁ½¸öÊÇ´ó¼Ò³£Óõģ¬ÈçÏ£º
//Create a new BarItem, specifying only the legend label for the bar. public BarItem(string);
//Create a new BarItem using the specified properties.
17 / 33
ZedGraph ÊôÐÔ¼°»ù´¡½Ì³Ì
public BarItem(string,double[],double[],Color);
BarItem myBar = myPane.AddBar( \1\null, y, Color.Red ); myBar.Bar.Fill = new Fill( Color.Red, Color.White, Color.Red );
ÕâÀïÓõÄÊÇÖ±½ÓÓÃPaneÀïµÄAddBarÀ´É趨ÖùÐΣ¬²¢ÇÒ·µ»ØÒ»¸öBarItemµÄÒýÓã¬ÈÃÓû§À´¶ÔÕâ¸öBar½øÐнøÒ»²½µÄÃèÊö¡£ÎÒÃÇ¿ÉÒÔ¿´µ½¹¹Ô캯ÊýÖÐµÄ ¡±Curve1¡±¾ÍÊÇÔÚLegendÖÐÒªÏÔʾµÄÎÄ×Ö(¹ØÓÚLegendÇë¿´µÚÒ»½Ú)¡£XÖáÉϵÄÖá±êÏȲ»É趨£¬ºóÃæ¸ú×ÅYÖáºÍÕâ¸öBarµÄÑÕÉ«¡£
µÚ¶þÐдúÂë¾ÍʹÓÃmyBarÕâ¸öÒýÓÃÀ´¶ÔÕâ¸öBar½øÐк졪°×¡ªºìµÄÑÕÉ«Ìî³ä¡£
// 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;
µÚÒ»ÐдúÂëÖ÷ÒªÊǶÔXÖáÉÏÖùÐεÄλÖÃ×öÒ»¸öÉ趨£¬Ä¬ÈÏÊǾÓÖÐ¶ÔÆë£¬Èç¹û²»É趨ÕâÒ»ÏîÄ¿£¬»òÕßÉ趨ÕâÒ»ÏîΪfalse£¬ÔòÖùÐÎÔÚ½çÃæÉϵÄÏÔʾÊǾÓÖеģ¬ÈçÏÂͼ£º(myPane.XAxis.IsTicsBetweenLabels = false;)
µÚ¶þ¡¢ÈýÐдúÂëµÄÒâ˼ÊÇÉ趨XÖáµÄ×ø±êÒÔÎı¾·½Ê½ÏÔʾ£¬Îı¾ÄÚÈÝÀ´×Ô
18 / 33
ZedGraph ÊôÐÔ¼°»ù´¡½Ì³Ì
string[] labels¡£
// Fill the axis area with a gradient
myPane.AxisFill = new Fill( Color.White,Color.FromArgb( 255, 255, 166), 90F ); // Fill the pane area with a solid color
myPane.PaneFill = new Fill( Color.FromArgb( 250, 250, 255) );
×îºóÁ½¾äÒ»¸öÊÇÉ趨PaneÖÐÖáµÄ±³¾°ÑÕÉ«£¬ÒÔ90¶ÈµÄ½Ç¶È´Ó°×µ½µ»ÆµÄ½¥±äЧ¹û£»ÁíÒ»¸öÊÇÉ趨PaneµÄ±³¾°É«£¬Êǵ»Ò°×É«£¬ÔÚͼÖÐÌåÏֵIJ»Ã÷ÏÔ£¬Çë´ó¼Ò×Ô¼º¸Ä³ÉColor.FromArgb( 250 , 250 , 0 )ÊÔÊÔЧ¹û°É¡£
×îºóÄǸöÈ«Ìî³äµÄÇúÏßͼÔÚµÚ1£¬2£¬3£¬4½ÚÖÐÒѾ¶¼½éÉܹýÁË£¬ÕâÀï²»ÔÙÖØ¸´£¬Çë×Ô¼º²Î¿´ÒÔǰµÄÕ½ڡ£
»ù±¾½Ì³Ìƪ--µÚÁù¡¢Æß½ÚHorizontalBarSampleDemo.csºÍStackedBarSampleDemo.cs½éÉÜ
ÕâÁ½½ÚÓëµÚÎå½ÚÏà±È£¬²¢Ã»Óб¾ÖÊÉϵÄÇø±ð£¬ËùÒÔÕâÀïÖ»¸ø³öÏàÓ¦µÄ´úÂ롢ʾÀýͼºÍ±ØÒªµÄ˵Ã÷¡£
using System;
using System.Drawing; using System.Collections; using ZedGraph;
namespace ZedGraph.Demo
{
///
19 / 33
ZedGraph ÊôÐÔ¼°»ù´¡½Ì³Ì
/// Summary description for SimpleDemo. ///
public class HorizontalBarSampleDemo : DemoBase {
public HorizontalBarSampleDemo() : base( \Project Horizontal Bar Chart Sample\
\Bar Sample\DemoType.Tutorial )
{
GraphPane myPane = base.GraphPane; // Set the title and axis labels
myPane.Title = \Horizontal Percent Stack Graph\ myPane.XAxis.Title = \ myPane.YAxis.Title = \
// Enter some random data values double[] y = { 100, 115, 15, 22, 98 }; double[] y2 = { 90, 60, 95, 35, 30 }; double[] y3 = { 20, 40, 105, 15, 30 };
// Generate a red bar with \in the legend
BarItem myCurve = myPane.AddBar( \y, null, Color.Red ); myCurve.Bar.Fill = new Fill( Color.Red, Color.White, Color.Red, 90F ); // Generate a blue bar with \in the legend
myCurve = myPane.AddBar( \y2, null, Color.Blue );
myCurve.Bar.Fill = new Fill( Color.Blue, Color.White, Color.Blue, 90F ); // Generate a green bar with \Maria\in the legend
myCurve = myPane.AddBar( \Maria\y3, null, Color.Green ); myCurve.Bar.Fill = new Fill( Color.Green, Color.White, Color.Green, 90F ); // Draw the Y tics between the labels instead of at the labels myPane.YAxis.IsTicsBetweenLabels = true; // Set the YAxis to text type
myPane.YAxis.Type = AxisType.Text;
string[] labels = { \\\\\}; myPane.YAxis.TextLabels = labels; myPane.XAxis.Max = 110;
20 / 33
¹²·ÖÏí92ƪÏà¹ØÎĵµ