chartControl ViewType.Bar 用法测试

时间:2022-09-17 22:21:36

使用方法 一、

chartControl  ViewType.Bar 用法测试

Datatable :

chartControl  ViewType.Bar 用法测试

 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 = ; i < ;i++ )
{
Random rd = new Random ();
DataRow dr = dt.NewRow();
dr["X轴"] = ("类别"+i.ToString()) ;
dr["线①"] = rd.Next(i*,(i+)*); ;
dr["线②"] = rd.Next(i * , (i + ) * );
dr["线③"] = rd.Next(i * , (i + ) * );
dr["线④"] = rd.Next(i * , (i + ) * );
dt.Rows.Add(dr);
} for (int i = ; 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);
}

使用方法二、

chartControl  ViewType.Bar 用法测试

代码如下:

Series series1 = new Series("测试", ViewType.Bar);
series1.Points.Add(new SeriesPoint("A", ));
series1.Points.Add(new SeriesPoint("B", ));
series1.Points.Add(new SeriesPoint("C", ));
series1.Points.Add(new SeriesPoint("D", )); this.chartControl1.Series.Add(series1);