DevExpress中chartControl中实现统计图功能

时间:2022-11-15 18:12:56
 public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
public Form1()
{
InitializeComponent();
LoadAll();
}
public void LoadAll()
{ //Series 对象表示数据系列,并且存储在 SeriesCollection 类中。
Series s1 = this.chartControl1.Series[];//新建一个series类并给控件赋值
s1.DataSource = ServiceData.GetClassCount();//设置实例对象s1的数据源
s1.ArgumentDataMember = "class";//绑定图表的横坐标
s1.ValueDataMembers[] = "count"; //绑定图表的纵坐标坐标
s1.LegendText = "人数";//设置图例文字 就是右上方的小框框
}
private void textEdit1_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.textEdit1.Text == "--请选择图表类型--")return; if (this.textEdit1.Text == "漏斗图")
{
DevExpress.XtraCharts.FunnelSeriesView funnelSeriesView1 = new DevExpress.XtraCharts.FunnelSeriesView();
this.chartControl1.Series[].View = funnelSeriesView1;
}
if (this.textEdit1.Text == "折线图")
{
DevExpress.XtraCharts.LineSeriesView lineSeriesView1 = new DevExpress.XtraCharts.LineSeriesView();
this.chartControl1.Series[].View = lineSeriesView1;
}
if (this.textEdit1.Text == "饼状图")
{
DevExpress.XtraCharts.PieSeriesView pieSeriesView1 = new DevExpress.XtraCharts.PieSeriesView();
this.chartControl1.Series[].View = pieSeriesView1;
}
if (this.textEdit1.Text == "柱形图")
{
DevExpress.XtraCharts.StackedBarSeriesView stackedBarSeriesView1 = new DevExpress.XtraCharts.StackedBarSeriesView();
this.chartControl1.Series[].View = stackedBarSeriesView1;
}
}
}
//创建测试数据表
public static class ServiceData
{
public static DataTable GetClassCount()
{
DataTable dt = new DataTable();
dt.Columns.Add("class", typeof(string));//年级
dt.Columns.Add("count", typeof(int)); //人数
dt.Rows.Add("一年级", );
dt.Rows.Add("二年级", );
dt.Rows.Add("三年级", );
dt.Rows.Add("四年级", );
dt.Rows.Add("五年级", );
dt.Rows.Add("六年级", );
dt.Rows.Add("七年级", );
dt.Rows.Add("八年级", );
dt.Rows.Add("九年级", );
return dt;
}
}

源文: http://blog.csdn.net/l1158513573/article/details/46728721  DevExpress中chartControl中实现统计图功能