100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > ChartControl控件绘制柱状图

ChartControl控件绘制柱状图

时间:2024-05-14 01:25:00

相关推荐

ChartControl控件绘制柱状图

1、新建一个DevExpress窗体(不要用WinForm窗体)

2、拖入一个chartcontrol控件

3、鼠标右键,点击run designer

添加两个series

4、代码设置

数据库表结构,我的想法是统计办事员和售货员的人数

数据库查询语句

select job,count(empno) as total from emp where job='办事员' group by job;select job,count(empno) as total from emp where job='售货员' group by job;

Form1.cs代码设置:

using DevExpress.XtraCharts;using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace DXApplication9{public partial class Form1 : DevExpress.XtraEditors.XtraForm{public Form1(){InitializeComponent();Bind();}public void Bind(){//Series类就是向图标里填充数据的类Series s1 = this.chartControl1.Series[0];Series s2 = this.chartControl1.Series[1];using (SqlConnection con=new SqlConnection("Data Source=.;Initial Catalog=test_10_23;User ID=sa;Password=123456;Connection Timeout=10")){string sql = "select job,count(empno) as total from emp where job='办事员' group by job;";string sql1 = "select job,count(empno) as total from emp where job='售货员' group by job;";SqlDataAdapter sda=new SqlDataAdapter(sql,con);SqlDataAdapter sda1 = new SqlDataAdapter(sql1, con);DataSet ds = new DataSet();DataSet ds1 = new DataSet();sda.Fill(ds);sda1.Fill(ds1);s1.DataSource = ds.Tables[0];s2.DataSource = ds1.Tables[0];s1.ArgumentDataMember = "job";//横坐标s2.ArgumentDataMember = "job";s1.ValueDataMembers[0] = "total";//纵坐标s2.ValueDataMembers[0] = "total";s1.LegendText = "办事员";s2.LegendText = "售货员";}}}}

5、启动程序

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。