CSharp_PivotGridControl和ChartControl简单实现<增强版>;
来源:互联网 发布:js date 初始化 编辑:程序博客网 时间:2024/04/30 03:10
->效果
->完整源码
using System;using System.Collections.Generic;using System.Data;using System.Windows.Forms;using DevExpress.XtraEditors;using System.Data.OleDb;using DevExpress.XtraPivotGrid;using DevExpress.LookAndFeel;using DevExpress.XtraCharts;namespace HelloWorld{ public partial class XtraForm_Main : XtraForm { // 图表 ChartControl chart; ChartControl bindedChart; public XtraForm_Main() { InitializeComponent(); } private void XtraForm_Main_Load(object sender, EventArgs e) { // 查看图表按钮 barBtnOperate.Alignment = DevExpress.XtraBars.BarItemLinkAlignment.Right; // 销售员汇总表 pivotGridCtrlConfig(); } /// <summary> /// 汇总表配置 /// </summary> private void pivotGridCtrlConfig() { BindingSource pivotBsource = new BindingSource(getDataSet("tableSales"), "tableSales"); pivotGridCtrlSales.DataSource = pivotBsource; // 行区域 PivotGridField fieldRegion = new PivotGridField("salesRegion", PivotArea.RowArea) { Caption = "地区" }; PivotGridField fieldSalesName = new PivotGridField("salesName", PivotArea.RowArea) { Caption = "销售员" }; // 列区域 PivotGridField fieldTime = new PivotGridField("salesTime", PivotArea.ColumnArea) { GroupInterval = PivotGroupInterval.DateYear /* 按年度分隔;*/, /*fieldTime.GroupInterval = PivotGroupInterval.DateMonth; // 按月份分隔;*/ /*fieldTime.GroupInterval = PivotGroupInterval.DateQuarter; //按季度分隔;*/ Caption = "销售时间" }; PivotGridField fieldProduct = new PivotGridField("product", PivotArea.ColumnArea) { Caption = "产品分类" }; // 过滤器 PivotGridField filterProduct = new PivotGridField("product", PivotArea.FilterArea) { Caption = "产品过滤" }; // 数据域 PivotGridField fieldDataPrice = new PivotGridField("extendedPrice", PivotArea.DataArea); fieldDataPrice.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric; fieldDataPrice.CellFormat.FormatString = "c0"; fieldDataPrice.Caption = "总额汇总"; // 添进控制器 pivotGridCtrlSales.Fields.AddRange(new PivotGridField[] { fieldRegion, fieldSalesName, fieldTime, fieldProduct, filterProduct, fieldDataPrice }); // 设置显示位置 fieldRegion.AreaIndex = 0; fieldSalesName.AreaIndex = 1; fieldProduct.AreaIndex = 0; fieldTime.AreaIndex = 1; // 感官 UserLookAndFeel.Default.UseWindowsXPTheme = false; UserLookAndFeel.Default.Style = LookAndFeelStyle.Skin; UserLookAndFeel.Default.SkinName = "Money Twins"; } /// <summary> /// 获取数据集 /// </summary> /// <param name="tablename"></param> /// <returns></returns> private static DataSet getDataSet(string tablename) { string connStr = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}\data\nwind.accdb", Application.StartupPath); OleDbConnection conn = new OleDbConnection(connStr); OleDbDataAdapter adp = new OleDbDataAdapter(string.Format("select * from {0}", tablename), conn); DataSet returnDs = new DataSet(); adp.Fill(returnDs, tablename); return returnDs; } /// <summary> /// 查看图表按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void barBtnOperate_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (bindedChart == null) { createSalesmanChart(); } } ChartControl salesmanChart; // 销售员总额图表; /// <summary> /// 创建销售员13、14年度销售总额图表 /// </summary> private void createSalesmanChart() { if (salesmanChart == null) { // /获取数据 // /access连接_切记access数据库日期用#包裹,而sqlserver用'包裹,要不会报错:标准表达式数据类型不匹配; string connStr = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}\data\nwind.accdb", Application.StartupPath); string sqlstr = "SELECT a.salesName, a.sumprice13, b.sumprice14 FROM " + "(SELECT salesName, SUM(extendedPrice) AS sumprice13 FROM tableSales WHERE salesTime >= #2013-01-01 00:00:00# AND salesTime <= #2013-12-31 23:59:59# GROUP BY salesName) AS a " + " INNER JOIN" + " (SELECT salesName, SUM(extendedPrice) AS sumprice14 FROM tableSales WHERE salesTime >= #2014-01-01 00:00:00# AND salesTime <= #2014-12-31 23:59:59# GROUP BY salesName ) AS b " + "ON a.salesName=b.salesName"; // /sqlserver连接 //string connStr = "provider=sqloledb;server=.\\SQLEXPRESS;uid=cyb;pwd=123456;database=TestDB"; //string sqlstr = "SELECT a.salesName, a.sumprice13, b.sumprice14 FROM " + // "(SELECT salesName, SUM(extendedPrice) AS sumprice13 FROM tableSales WHERE salesTime BETWEEN '2013-01-01' AND '2013-12-31' GROUP BY salesName) AS a " + // " INNER JOIN" + // " (SELECT salesName, SUM(extendedPrice) AS sumprice14 FROM tableSales WHERE salesTime BETWEEN '2014-01-01' AND '2014-12-31' GROUP BY salesName ) AS b " + // "ON a.salesName=b.salesName"; OleDbConnection conn = new OleDbConnection(connStr); OleDbDataAdapter adp = new OleDbDataAdapter(sqlstr, conn); DataSet sumDs = new DataSet(); adp.Fill(sumDs, "salesmanSum"); // 销售员年度总额; // 总额图表 salesmanChart = new ChartControl(); // 系列 Series year13Series = new Series("13年度总额", ViewType.Bar); Series year14Series = new Series("14年度总额", ViewType.Bar); // 系列添加 salesmanChart.Series.AddRange(new Series[] { year13Series, year14Series }); // 系列数据绑定配置 year13Series.DataSource = sumDs.Tables["salesmanSum"]; year14Series.DataSource = sumDs.Tables["salesmanSum"]; // 系列数据点设置 year13Series.ArgumentScaleType = ScaleType.Qualitative; year13Series.ArgumentDataMember = "salesName"; year13Series.ValueScaleType = ScaleType.Numerical; year13Series.ValueDataMembers.AddRange(new string[] { "sumprice13" }); year14Series.ArgumentScaleType = ScaleType.Qualitative; year14Series.ArgumentDataMember = "salesName"; year14Series.ValueScaleType = ScaleType.Numerical; year14Series.ValueDataMembers.AddRange(new string[] { "sumprice14" }); // 视觉设置 ((XYDiagram)salesmanChart.Diagram).AxisY.Visible = false; // 图表添加 salesmanChart.Dock = DockStyle.Bottom; pivotGridCtrlSales.Controls.Add(salesmanChart); } } /// <summary> /// 创建数据绑定图表 /// </summary> private void createBindedChart() { // 图表数据集 DataSet chartds = getDataSet("tableYearSum"); if (chartds != null) { // 图表 bindedChart = new ChartControl(); // 系列 Series priceSeries = new Series("销售总额", ViewType.Bar); Series productSeries = new Series("销售总量", ViewType.Bar); // 系列添加 bindedChart.Series.AddRange(new Series[] { priceSeries, productSeries}); // 系列数据绑定配置 priceSeries.DataSource = chartds.Tables["tableYearSum"]; productSeries.DataSource = chartds.Tables["tableYearSum"]; // 系列数据点设置 priceSeries.ArgumentScaleType = ScaleType.Qualitative; priceSeries.ArgumentDataMember = "timeyear"; priceSeries.ValueScaleType = ScaleType.Numerical; priceSeries.ValueDataMembers.AddRange(new string[] { "sumPrice"}); productSeries.ArgumentScaleType = ScaleType.Qualitative; productSeries.ArgumentDataMember = "timeyear"; productSeries.ValueScaleType = ScaleType.Numerical; productSeries.ValueDataMembers.AddRange(new string[] { "sumProduct" }); // 视觉设置 //((SideBySideBarSeriesView)priceSeries.View).ColorEach = true; // 每柱形颜色不一样; ((XYDiagram)bindedChart.Diagram).AxisY.Visible = false; // y轴不可见; //bindedChart.Legend.Visible = false; // 说明不可见; // 图表添加 bindedChart.Dock = DockStyle.Bottom; pivotGridCtrlSales.Controls.Add(bindedChart); } } /// <summary> /// 创建静态数据图表 /// </summary> private void createStaticChart() { // 图表 chart = new ChartControl(); // 系列 Series seriesBar = new Series("柱形", ViewType.Bar); // 数据点 seriesBar.Points.Add(new SeriesPoint("2014", 4563)); seriesBar.Points.Add(new SeriesPoint("2013", 3365)); seriesBar.Points.Add(new SeriesPoint("2012", 2013)); seriesBar.Points.Add(new SeriesPoint("2011", 1345)); seriesBar.Points.Add(new SeriesPoint("2010", 7561)); seriesBar.Points.Add(new SeriesPoint("2009", 5216)); // 添加系列进图表 chart.Series.AddRange(new Series[] { seriesBar }); // 柱顶标签 ((BarSeriesLabel)seriesBar.Label).Visible = true; ((BarSeriesLabel)seriesBar.Label).ResolveOverlappingMode = ResolveOverlappingMode.Default; seriesBar.PointOptions.PointView = PointView.ArgumentAndValues; // 添加图表进控制器 chart.Dock = DockStyle.Bottom; pivotGridCtrlSales.Controls.Add(chart); } }}
0 0
- CSharp_PivotGridControl和ChartControl简单实现<增强版>;
- CSharp_PivotGridControl和ChartControl简单实现;
- Dev GridControl 和chartControl、SplitterControl 简单操作
- DevExpress控件ChartControl简单案例
- DevExpress ChartControl控件实现图表
- 增强学习简单案例实现
- DevExpress中chartControl中实现统计图功能
- python实现增强版ping
- 一个简单的Echo Server的Java实现(增强版)
- OC实现猜拳游戏2.0(更简单方法,用两个对象、继承、条件表达式、@proterty增强和点语法)
- 增强学习系列之(二):实现一个简单的增强学习的例子
- 增强学习系列之(二):实现一个简单的增强学习的例子
- chartControl使用方法
- ChartControl属性
- ChartControl柱状图
- Dev ChartControl
- 图像一些简单增强
- 资产主数据增强的配置和实现
- ADO查询站SQLServer,字段类型
- Spark 学习笔记
- ActionContext和ServletActionContext小结
- HDU 1535
- leetcode: Merge Two Sorted Lists
- CSharp_PivotGridControl和ChartControl简单实现<增强版>;
- (1)HTML5简介
- 堆和栈的区别
- 取文本中间
- 基于XMPP Openfire Smack 的IM通讯----监听别的用户发送过来的会话
- 算术级数
- 多说社会化评论插件PHP版网站登陆同步 单项登陆 网站用户登陆同步到多说登陆框
- ZooKeeper是什么
- Javascript跨域访问解决方案