ZedGraph控件属性及基础教程详解(2003)

ZedGraph 属性及基础教程

// Make the bars horizontal by setting bar base axis to Y myPane.BarBase = BarBase.Y; // Make the bars percent stack type myPane.BarType = BarType.PercentStack; // Fill the axis background with a color gradient myPane.AxisFill = new Fill( Color.White, Color.FromArgb( 255, 255, 166), 90F ); // Fill the legend background with a color gradient myPane.Legend.Fill = new Fill( Color.White, Color.FromArgb( 255, 255, 250), 90F ); // Fill the pane background with a solid color

myPane.PaneFill = new Fill( Color.FromArgb( 250, 250, 255) ); base.ZedGraphControl.AxisChange(); } }

}

using System;

using System.Drawing;

21 / 33

ZedGraph 属性及基础教程

using System.Collections; using ZedGraph;

namespace ZedGraph.Demo

{

///

/// Summary description for SimpleDemo. ///

public class StackedBarSampleDemo : DemoBase {

public StackedBarSampleDemo() : base( \Project Stacked Bar Chart Sample\Bar Sample\DemoType.Tutorial ) {

GraphPane myPane = base.GraphPane; // Set the title and axis labels myPane.Title = \Stats\ myPane.XAxis.Title = \Cats\ myPane.YAxis.Title = \

// Make up some data points

string[] labels = { \\\\\\}; double[] y = { 100, 115, 75, 22, 98, 40 }; double[] y2 = { 120, 175, 95, 57, 113, 110 }; double[] y3 = { 204, 192, 119, 80, 134, 156 };

// Generate a red bar with \1\in the legend

BarItem myCurve = myPane.AddBar( \null, y, Color.Red ); // Fill the bar with a red-white-red color gradient for a 3d look myCurve.Bar.Fill = new Fill( Color.Red, Color.White, Color.Red ); // Generate a blue bar with \2\in the legend myCurve = myPane.AddBar( \null, y2, Color.Blue ); // Fill the bar with a Blue-white-Blue color gradient for a 3d look myCurve.Bar.Fill = new Fill( Color.Blue, Color.White, Color.Blue );

22 / 33

ZedGraph 属性及基础教程

// Generate a green bar with \3\in the legend

myCurve = myPane.AddBar( \null, y3, Color.Green ); // Fill the bar with a Green-white-Green color gradient for a 3d look myCurve.Bar.Fill = new Fill( Color.Green, Color.White, Color.Green ); // 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;

// Set the bar type to stack, which stacks the bars by automatically accumulating the values myPane.BarType = BarType.Stack; base.ZedGraphControl.AxisChange(); } }

}

这两个图的区别就是基轴不同,一个是以X轴为基轴,一个是以Y轴为基轴,ZedGraph中有相应的属性,很方便的在两个轴之间转换。如下:

myPane.BarBase = BarBase.Y;

下面我主要说说myPane.BarType。

BarType是一个枚举,共有六项,分别为Cluster、ClusterHiLow、Overlay、SortedOverlay、Stack和PercentStack。

Cluster和ClusterHiLow是让多个同一个基类Bar依次排开,Cluster还可以使用来自IPointList的“Z”的值来定义每一个Bar的底部。

myPane.BarType = BarType.Cluster;或者myPane.BarType = BarType.ClusterHiLow;如下图:

23 / 33

ZedGraph 属性及基础教程

Overlay和SortedOverlay故名思意,就是柱形按坐标相互覆盖。不同之处在于Overlay是按照哪个先画哪个在前的原则(注意这里不是按后画把先画的柱形覆盖的原则,而是正好相反按先画在前原则)。 SortedOverlay是按位标的大小,按小的位标在前,大的位标在后的原则来绘图的。 如下两图,第一个是按Overlay,第二个是SortedOverlay。

24 / 33

联系客服:779662525#qq.com(#替换为@)