ChartControl控件绘制柱状图
1、新建一个DevExpress窗体(不要用WinForm窗体)![在这里插入图片描述](https://img-blog.csdnimg.cn/20201031164659516.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzUzNzI0,size_16,color_FFFFFF,t_70#pic_center)
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 System.ComponentModel;
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 = "售货员";
}
}
}
}
2301_79118893: 大佬,求源码!邮箱1208649010@qq.com
2401_84118810: 已关注 邮箱2648310836@qq.com 谢谢大佬,蹲蹲
qq_44785365: 我这边是某加速器,次次都是它。现在我只要报错弹不出去直接去结束那个软件进程就行了,都不用看进程id。
筑梦东海: 你好,可以发个源码和数据库吗,万分感谢1878467131@qq.com
玉泽写: 支持一下,细节很到位!【我也写了一些相关领域的文章,希望能够得到博主的指导,共同进步!】