使用方法 一、
Datatable :
chartControl1.Series.Clear(); DataTable dt = new DataTable(); dt.Columns.Add("X轴",Type.GetType("System.String")); dt.Columns.Add("线①", Type.GetType("System.Int32")); dt.Columns.Add("线②", Type.GetType("System.Int32")); dt.Columns.Add("线③", Type.GetType("System.Int32")); dt.Columns.Add("线④", Type.GetType("System.Int32")); for (int i = 0; i < 10;i++ ) { Random rd = new Random (); DataRow dr = dt.NewRow(); dr["X轴"] = ("类别"+i.ToString()) ; dr["线①"] = rd.Next(i*10,(i+1)*10); ; dr["线②"] = rd.Next(i * 10, (i + 1) * 10); dr["线③"] = rd.Next(i * 10, (i + 1) * 10); dr["线④"] = rd.Next(i * 10, (i + 1) * 10); dt.Rows.Add(dr); } for (int i = 1; i < dt.Columns.Count;i++ ) { // 柱状图里的第二柱 //第一个参数 设置四个竖条的标注 Series Series2 = new Series(dt.Columns[i].ColumnName, ViewType.Bar); Series2.DataSource = dt; Series2.ArgumentScaleType = ScaleType.Qualitative; Series2.ArgumentDataMember = "X轴"; //设置公共的X轴值(刻度) Series2.ValueScaleType = ScaleType.Numerical; //设置 单个Series2 Y轴的(值) Series2.ValueDataMembers.AddRange(new string[] { dt.Columns[i].ColumnName }); chartControl1.Series.Add(Series2); }
使用方法二、
代码如下:
Series series1 = new Series("测试", ViewType.Bar); series1.Points.Add(new SeriesPoint("A", 5)); series1.Points.Add(new SeriesPoint("B", 8)); series1.Points.Add(new SeriesPoint("C", 2)); series1.Points.Add(new SeriesPoint("D", 17)); this.chartControl1.Series.Add(series1);