Chart圖表解釋說明:工具
第一步:使用VS建立Winform項目;this
第二步:工具箱中拖入Chart控件;spa
第三步:全部控件拖入其餘控件以下圖所示:.net
using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; namespace ZB.PISS.StatisticsSys { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { List<int> x = new List<int> { 1, 2, 3, 4, 5 }; List<int> a = new List<int> { 11, 22, 30, 40, 50 }; List<int> b = new List<int> { 22, 14, 35, 24, 44 }; List<int> c = new List<int> { 33, 22, 33, 44, 28 }; var dd = chartDemo.Series; this.chartDemo.Series["name1"].Points.DataBindXY(x, a); this.chartDemo.Series["name2"].Points.DataBindXY(x, b); this.chartDemo.Series["name3"].Points.DataBindXY(x, c);
Winfrom chart DataBindXY X內容顯示不全解決方法以下:code
chartImage.ChartAreas["ChartArea1"].AxisX.LabelAutoFitStyle = LabelAutoFitStyles.None;
chartImage.ChartAreas["ChartArea1"].AxisX.LabelStyle.Interval = 1;
chartImage.ChartAreas["ChartArea1"].AxisX.LabelStyle.IsStaggered = false;orm
//Chart Title this.chartDemo.Titles.Add("人員信息統計").Alignment = ContentAlignment.MiddleCenter; Color[] arr = chartDemo.PaletteCustomColors; this.cmbPattern.DataSource = PatternList(); this.cmbType.DataSource = SeriesTypeList(); //Axis Title this.chartDemo.ChartAreas[0].AxisX.Title = "月份信息"; this.chartDemo.ChartAreas[0].AxisY.Title = "數量信息"; //Lable // #VALX 顯示當前圖例的X軸的對應文本(或數據) //#VAL, #VALY, 顯示當前圖例的Y軸的對應文本(或數據) //#VALY2, #VALY3, 顯示當前圖例的輔助Y軸的對應文本(或數據) //#SER: 顯示當前圖例的名稱 //#LABEL 顯示當前圖例的標籤文本 //#INDEX 顯示當前圖例的索引 //#PERCENT 顯示當前圖例的所佔的百分比 //#TOTAL 總數量 //#LEGENDTEXT 圖例文本 this.chartDemo.Series[0].Label = "#VAL"; this.chartDemo.Series[1].Label = "#VAL"; this.chartDemo.Series[2].Label = "#VAL"; //Marker this.chartDemo.Series[0].MarkerSize = 20; this.chartDemo.Series[1].MarkerSize = 20; this.chartDemo.Series[2].MarkerSize = 20; this.chartDemo.Series[0].MarkerStyle = MarkerStyle.Circle; this.chartDemo.Series[1].MarkerStyle = MarkerStyle.Square; this.chartDemo.Series[2].MarkerStyle = MarkerStyle.Diamond; } #region ChartType public List<string> SeriesTypeList() { List<string> list = new List<string>(); foreach (string item in Enum.GetNames(typeof(SeriesChartType))) { list.Add(item); } return list; } private void cmbType_SelectedValueChanged(object sender, EventArgs e) { try { SeriesChartType type = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), this.cmbType.Text); this.chartDemo.Series["name1"].ChartType = type; this.chartDemo.Series["name2"].ChartType = type; this.chartDemo.Series["name3"].ChartType = type; } catch { return; } } #endregion #region Pattern public List<string> PatternList() { List<string> list = new List<string>(); foreach (string item in Enum.GetNames(typeof(ChartColorPalette))) { list.Add(item); } return list; } private void cmbPattern_SelectedValueChanged(object sender, EventArgs e) { ChartColorPalette palette = (ChartColorPalette)Enum.Parse(typeof(ChartColorPalette), this.cmbPattern.Text); this.chartDemo.Palette = palette; } #endregion } }
運行效果以下:blog
資源源碼下載地址:http://download.csdn.net/my Winfrom Chart索引
補充:資源
一:實現3D效果源碼
private void comboBox1_SelectedValueChanged(object sender, EventArgs e) { if (this.comboBox1.Text.Equals("3D")) { //this.chartDemo.ChartAreas[0].Area3DStyle.Enable3D = true; //開啓三維模式的緣由是爲了不標籤重疊 this.chartDemo.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//開啓三維模式;PointDepth:厚度BorderWidth:邊框寬 this.chartDemo.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度 this.chartDemo.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//傾斜度(0~90) this.chartDemo.ChartAreas["ChartArea1"].Area3DStyle.LightStyle = LightStyle.Realistic;//表面光澤度 this.chartDemo.ChartAreas["ChartArea1"].AxisX.Interval = 1; //決定x軸顯示文本的間隔,1爲強制每一個柱狀體都顯示,3則間隔3個顯示 this.chartDemo.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("宋體", 9, FontStyle.Regular); this.chartDemo.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false; } else { this.chartDemo.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false; } }