c# chart控件基本使用方法(柱状图和饼图)



1
chartType.Series.Clear(); 2 chartType.ChartAreas.Clear(); 3 if (rbtnPie.Checked) 4 { 5 Series Series1 = new Series(); 6 chartType.Series.Add(Series1); 7 chartType.Series["Series1"].ChartType = SeriesChartType.Pie; 8 chartType.Legends[0].Enabled = true; 9 chartType.Series["Series1"].LegendText = "#INDEX:#VALX";//开启图例 10 chartType.Series["Series1"].Label = "#INDEX:#PERCENT"; 11 chartType.Series["Series1"].IsXValueIndexed = false; 12 chartType.Series["Series1"].IsValueShownAsLabel = false; 13 chartType.Series["Series1"]["PieLineColor"] = "Black";//连线颜色 14 chartType.Series["Series1"]["PieLabelStyle"] = "Outside";//标签位置 15 chartType.Series["Series1"].ToolTip = "#VALX";//显示提示用语 16 ChartArea ChartArea1 = new ChartArea(); 17 chartType.ChartAreas.Add(ChartArea1); 18 //开启三维模式的原因是为了避免标签重叠 19 chartType.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽 20 chartType.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度 21 chartType.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 45;//倾斜度(0~90) 22 chartType.ChartAreas["ChartArea1"].Area3DStyle.LightStyle = LightStyle.Realistic;//表面光泽度 23 } 24 if (rbtnBar.Checked) 25 { 26 Series Series1 = new Series(); 27 chartType.Series.Add(Series1); 28 chartType.Series["Series1"].ChartType = SeriesChartType.Column; 29 chartType.Legends[0].Enabled = false; 30 chartType.Series["Series1"].LegendText = ""; 31 chartType.Series["Series1"].Label = "#VALY"; 32 chartType.Series["Series1"].ToolTip = "#VALX"; 33 chartType.Series["Series1"]["PointWidth"] = "0.5"; 34 ChartArea ChartArea1 = new ChartArea(); 35 chartType.ChartAreas.Add(ChartArea1); 36 //开启三维模式的原因是为了避免标签重叠 37 chartType.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽 38 chartType.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度 39 chartType.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//倾斜度(0~90) 40 chartType.ChartAreas["ChartArea1"].Area3DStyle.LightStyle = LightStyle.Realistic;//表面光泽度 41 chartType.ChartAreas["ChartArea1"].AxisX.Interval = 1; //决定x轴显示文本的间隔,1为强制每个柱状体都显示,3则间隔3个显示 42 chartType.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font =new Font("宋体", 9, FontStyle.Regular); 43 chartType.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false; 44 } 45 46 chartType.Series[0].XValueMember = "name"; 47 chartType.Series[0].YValueMembers = "sumcount";

 

posted on 2013-08-28 15:18  Mis_Eur  阅读(18113)  评论(1编辑  收藏  举报

导航