关键代码:

using System;
using System.Data;
using System.Windows.Forms;
using CSharpUtilHelpV2;
using DevExpress.XtraCharts;

namespace DevExpressChart
{
    public partial class winProduct : Form
    {
        public winProduct()
        {
            InitializeComponent();
        }
        static readonly string AccessFullPath = string.Format(@"{0}\Northwind.MDB", AppDomain.CurrentDomain.BaseDirectory);
        static DataTable ProductList = null;
        AccessUtilsV2 AccessHelper = null;
        private void winChat_Load(object sender, EventArgs e)
        {
            AccessHelper = new AccessUtilsV2(AccessFullPath);
            ProductList = AccessHelper.ExecuteDataTable("select * from Products", null);
            BuilderDevChart();
        }
        private void BuilderDevChart()
        {
            if (ProductList != null)
            {
                Series _barSeries = new Series("测试", ViewType.Bar);
                _barSeries.ArgumentDataMember = "ProductName";//x轴
                _barSeries.ValueDataMembers[0] = "UnitPrice";//Y轴
                _barSeries.DataSource = ProductList;
                _barSeries.AddDataFilter("CategoryID", 4, DataFilterCondition.Equal);
                _barSeries.SetColorEach(true);
                chartControl1.Series.Add(_barSeries);
                _barSeries.LegendPointOptions.PointView = PointView.ArgumentAndValues;

                //chartControl1.SeriesDataMember = "UnitPrice";
                //chartControl1.SeriesTemplate.ValueDataMembers[0] = "UnitPrice";
                //chartControl1.SeriesTemplate.ArgumentDataMember = "ProductName";
                //chartControl1.SeriesTemplate.ArgumentScaleType = ScaleType.Qualitative;
                //chartControl1.SeriesTemplate.AddDataFilter("CategoryID", 4, DataFilterCondition.Equal);
                //chartControl1.SeriesTemplate.LegendPointOptions.PointView = PointView.ArgumentAndValues;
                chartControl1.SetXLableAngle(-35);
                chartControl1.SetCrosshair(true);

                chartControl1.Legend.Direction = LegendDirection.LeftToRight;
                chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Center;
                chartControl1.Legend.AlignmentVertical = LegendAlignmentVertical.BottomOutside;
                chartControl1.DataSource = ProductList;

                chartControl1.AddTitle("Product List");
                //--------------------------
            }
        }
    }
}

------------------------------------------------------------------------------------------------------

using DevExpress.Utils;
using DevExpress.XtraCharts;

namespace DevExpressChart
{
    public static class ChartUtils
    {
        /// <summary>
        /// 增加数据筛选
        /// </summary>
        /// <param name="SeriesBase">Series</param>
        /// <param name="columnName">列名称</param>
        /// <param name="value">列名称对应的筛选数值</param>
        /// <param name="dataFilterCondition">DataFilterCondition枚举</param>
        public static void AddDataFilter(this SeriesBase series, string columnName, object value, DataFilterCondition dataFilterCondition)
        {
            series.DataFilters.Add(new DataFilter(columnName, value.GetType().FullName, dataFilterCondition, value));
        }

        /// <summary>
        /// 设置X轴Lable角度
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="angle">角度</param>
        public static void SetXLableAngle(this ChartControl chart, int angle)
        {
            XYDiagram _xyDiagram = (XYDiagram)chart.Diagram;
            if (_xyDiagram != null)
                _xyDiagram.AxisX.Label.Angle = angle;
        }
        /// <summary>
        ///  设置Y轴Lable角度
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="angle">角度</param>
        public static void SetYLableAngle(this ChartControl chart, int angle)
        {
            XYDiagram _xyDiagram = (XYDiagram)chart.Diagram;
            _xyDiagram.AxisY.Label.Angle = angle;
        }
        /// <summary>
        /// 设置ColorEach
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="colorEach">是否设置成ColorEach</param>
        public static void SetColorEach(this Series series, bool colorEach)
        {
            SeriesViewColorEachSupportBase colorEachView = (SeriesViewColorEachSupportBase)series.View;
            if (colorEachView != null)
            {
                colorEachView.ColorEach = colorEach;
            }
        }
        /// <summary>
        /// 设置是否显示十字标线
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="crosshair">是否显示十字标线</param>
        public static void SetCrosshair(this ChartControl chart, bool crosshair)
        {
            chart.CrosshairEnabled = crosshair ? DefaultBoolean.True : DefaultBoolean.False;
            chart.CrosshairOptions.ShowArgumentLabels = crosshair;
            chart.CrosshairOptions.ShowArgumentLine = crosshair;
            chart.CrosshairOptions.ShowValueLabels = crosshair;
            chart.CrosshairOptions.ShowValueLine = crosshair;
        }
        /// <summary>
        /// 新增ChartControl的Title文字
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="title">Title文字</param>
        public static void AddTitle(this ChartControl chart, string title)
        {
            ChartTitle _title = new ChartTitle();
            _title.Text = title;
            chart.Titles.Add(_title);
        }
        /// <summary>
        /// 饼状Series设置成百分比显示
        /// </summary>
        /// <param name="series">Series</param>
        public static void SetPiePercentage(this Series series)
        {
            if (series.View is PieSeriesView)
            {
                ((PiePointOptions)series.PointOptions).PercentOptions.ValueAsPercent = true;
                ((PiePointOptions)series.PointOptions).ValueNumericOptions.Format = NumericFormat.Percent;
                ((PiePointOptions)series.PointOptions).ValueNumericOptions.Precision = 0;
            }
        }
    }
}

运行效果:

希望有所帮助!谢谢!

[DevExpress]ChartControl之柱状图示例的更多相关文章

  1. [DevExpress]ChartControl之SeriesTemplate示例

    关键代码: using System; using System.Data; using System.Windows.Forms; using CSharpUtilHelpV2; using Dev ...

  2. [DevExpress]ChartControl之基准线示例

    关键代码: /// <summary> /// 创建基准线ConstantLine /// </summary> /// <param name="chart& ...

  3. [DevExpress]ChartControl之滚动条示例

    关键代码: /// <summary> /// 设置ChartControl滚动条[默认X,Y轴都出现] /// </summary> /// <param name=& ...

  4. DevExpress ChartControl大数据加载时有哪些性能优化方法

    DevExpress ChartControl加载大数据量数据时的性能优化方法有哪些? 关于图表优化,可从以下几个方面解决: 1.关闭不需要的可视化的元素(如LineMarkers, Labels等) ...

  5. [DevExpress]ChartControl之时间轴示例

    关键代码: using System; using System.Data; using System.Windows.Forms; using DevExpress.XtraCharts; name ...

  6. DevExpress ChartControl 柱状图的使用【转】

    //中心业务平台的“热门岗位信息监测”柱状图 public partial class HotJobInfo : UserControl     {         private object _o ...

  7. Devexpress ChartControl 柱状图简单例子

    //using DevExpress.XtraEditors; //using DevExpress.XtraCharts; // Create an empty chart. ChartContro ...

  8. [DevExpress]ChartControl之创建X,Y轴Title示例

    关键代码: /// <summary> /// 设置X轴Title /// </summary> /// <param name="chart"> ...

  9. [DevExpress]ChartControl之饼状图百分比示例

    关键代码: using System; using System.Data; using System.Windows.Forms; using DevExpress.XtraCharts; name ...

随机推荐

  1. Xcode代码格式化教程,可自定义样式

    来源:iOS_小松哥 链接:http://www.jianshu.com/p/a725e24d7835 为什么要格式化代码 当团队内有多人开发的时候,每个人写的代码格式都有自己的喜好,也可能会忙着写代 ...

  2. IIS 之 HTTP 错误 403.14 - Forbidden

    错误如下图所示: 其实,这个提示下面已经交代了怎么解决问题,现在告诉大家具体的详细步骤. 方法一:配置" 默认文档 " 方法二:启用" 目录浏览 "

  3. jquery学习笔记2

    1.点击时文字消失,失去焦点时文字再出现 <input type="text" value="郭强" onfocus="if(value=='郭 ...

  4. label

    label的使用 以前只知道使用并没太注意一些细节 话说<label><input type="checkbox"/>5星</label>就可以 ...

  5. Oracle基础 锁

    一.锁 数据库是一个多用户使用的共享资源.当多个用户并发地存储数据时,数据库中就会产生多个事务同时存取同一数据的情况.若对并发操作不加控制就可能会读取和存储不正确的数据,破坏数据库的一致性. 锁是实现 ...

  6. VMware系统运维(十一)部署虚拟化桌面 Horizon View 5.2 HTML ACCESS安装

    如果你希望在浏览器上面能够连接到用户桌面,那么HTML ACCESS是必须安装的,下面开始安装. 1.点击红框文件 2.打开安装向导,点击"下一步" 3.接受协议,点击" ...

  7. hdu 3308 LCIS 线段树

    昨天热身赛的简单版:LCIS.昨天那题用树链剖分,不知道哪里写错了,所以水了水这题看看合并.更新方式是否正确,发现没错啊.看来应该是在树链剖分求lca时写错了... 题目:给出n个数,有两种操作: 1 ...

  8. 把当前时间(NSDate)转为字符串 - 获取当前时间的Day

    1.把当前时间转为字符串 (NSDate与北京时间相隔8小时,格式化之后就是北京时间) NSDate *date = [NSDate date]; NSDateFormatter *dateForma ...

  9. IOS NSNotificationCenter 的使用

    在Android中,为了解耦各个模块的耦合度,我们会使用很多方式,当然最简单而且效率最高的方式就是使用事件总线的方式进行消息分发,但是Android中并没有自带的消息分发机制,需要使用第三方库,比如E ...

  10. Git之基本命令

    先介绍一下Git: Git是一个分布式的版本控制系统,最初由Linus Torvalds编写,用作Linux内核代码的管理.在推出后,Git在其它项目中也取得了很大成功,尤其是在Ruby社区中.目前, ...