微软图表控件使用拾遗

 1 //演示文档比较漂亮,提取参数如下:
2 chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;//圆角,阴影有Emboss,Raised和Sunken
3 chart1.Width = Unit.Pixel(500);//设定宽高后,里面的图会自动随之增缩
4 chart1.AntiAliasing = AntiAliasingStyles.Graphics;//图片反锯齿,默认似乎为这个选项
5 chart1.BackColor = System.Drawing.Color.FromArgb(211, 223, 240);//例子中的配色方案
6 chart1.BackGradientStyle = GradientStyle.TopBottom;
7
8 //运行时生成图表示例
9 //chart
10 chart1.Width = Unit.Pixel(800);
11 //title
12 chart1.Titles.Add("图表标题");
13 //lengend
14 Legend l1= chart1.Legends.Add("l1");
15 l1.BackColor = System.Drawing.Color.Transparent;//图示区透明
16 //area
17 ChartArea ca1= chart1.ChartAreas.Add("ca1");
18 ca1.BackColor = System.Drawing.Color.Transparent;
19 //series
20 Series s1 = chart1.Series.Add("预订数量");
21 Series s2 = chart1.Series.Add("总收入");
22 s1.ChartType = SeriesChartType.StackedColumn;
23 s2.ChartType = SeriesChartType.StackedColumn;
24 //****重要,此节在设计时是找不到的,只能在运行时手写代码****//
25 s1["DrawingStyle"] = "Cylinder";//Cylinder、Emboss、LightToDark、Wedge、Default
26 s2["DrawingStyle"] = "Cylinder";
27 //******//
28 s1.LabelForeColor = System.Drawing.Color.White;//label的颜色
29 //****注意第三个参数的用法****//
30 s1.Points.DataBind(dv, "hospital_name", "reserve_count", "tooltip=reserve_count,label=reserve_count");
31 s2.Points.DataBind(dv, "hospital_name", "reserve_sum", "tooltip=reserve_sum,label=reserve_sum");
32
33 //******注意: 当X轴有值被隐藏时,显示所有X轴的值*****//
34 ca1.AxisX.Interval = 1;
35
36 //饼图、甜甜圈图的部分演示
37 ChartArea ca2 = chart2.ChartAreas.Add("ca2");
38 ca2.BackColor = System.Drawing.Color.Transparent;
39 Series ss2 = chart2.Series.Add("test");
40 ss2.ChartType = SeriesChartType.Doughnut;
41 ss2.Points.DataBind(dv, "hospital_name", "reserve_count", "tooltip=reserve_count");
42 //******注意以下函数的用法*****//
43 ss2.Label = "#PERCENT";
44 //s2.ToolTip = "#VALY{C}";//上面databind的时候已经设过了,这是另一种设法
45 ss2.LegendText = "#VALX"; //此处演示图例和label用不同的值,(默认全都是X的值),两者都直接在series上设
46 ss2.LegendToolTip = "#PERCENT";
47 //******自定义参数的用法得详见文档*********//
48 //http://msdn.microsoft.com/en-us/library/dd456764.aspx
49 ss2.CustomProperties = "DoughnutRadius=75, PieDrawingStyle=Concave, MinimumRelativePieSize=20, LabelStyle=Inside";
50 //PieDrawingStyle值有Default, SoftEdge, Concave;
51 ss2.BackGradientStyle = GradientStyle.DiagonalLeft;//图片光泽,渐变,(3D无效)
52 //ss2.BackHatchStyle = ChartHatchStyle.ForwardDiagonal;//图片的底纹
53 //ss2.BorderColor = System.Drawing.Color.Red;//可见,series的属性都作用在图片的每一个部分,比如一个饼的每一块,每一个图例,此例为每一块加边框
54 ss2.LabelForeColor = System.Drawing.Color.Black;//label文字颜色
55 //ss2.LabelBackColor = System.Drawing.Color.White;//label文字背景色,以防止文字与图片文字颜色相同
56 ss2.Palette = ChartColorPalette.BrightPastel;//配色方案
57
58 //辅助线的样式
59 System.Drawing.Color linecolor = System.Drawing.Color.FromArgb(100, 150, 200);
60 c31.AxisX.MajorGrid.LineColor = linecolor; //X轴辅助线颜色,与X轴垂直
61 c31.AxisY.MajorGrid.LineColor = linecolor;
62 c31.AxisX.MajorTickMark.LineColor = linecolor; //X轴刻度颜色
63 c31.AxisY.MajorTickMark.LineColor = linecolor;
64 c31.AxisX.LineColor = linecolor; //X轴颜色
65 c31.AxisY.LineColor = linecolor;

你可能感兴趣的:(图表控件)