//中心业务平台的“热门岗位信息监测”柱状图

public partial class HotJobInfo : UserControl
    {
        private object _objLock = new object();

private delegate void getDataHandler();

/// <summary>
        /// 热门岗位数据
        /// </summary>
        private BarGraghData _barGraghData = null;

public HotJobInfo()
        {
            InitializeComponent();
            //获取热门岗位数据
            //异步获取数据,绘制图表
            getDataHandler handler = new getDataHandler(GetHotJobDataInfo);
            IAsyncResult result = handler.BeginInvoke(new AsyncCallback(showLine), "AsycState:OK");
        }

private void showLine(IAsyncResult result)
        {
            try
            {
                this.Invoke(
                            new Action(
                            delegate
                            {
                                //绘制图表
                                ToLineGragh();
                            }));
            }
            catch { }
        }

/// <summary>
        /// 获取热门岗位信息数据
        /// </summary>
        private void GetHotJobDataInfo()
        {
            try
            {
                lock (_objLock)
                {
                    //向服务器请求数据
                    Random ran = new Random();
                    int sjd = ran.Next(1, 1000);
                    string addr = ConfigurationManager.AppSettings["ServiceAddr"].ToString();
                    //去掉地址结尾的'/',否则请求中会出现两个'/',而导致请求失败
                    string url =
string.Format(@"{0}/JobInfoCheck/GetHotJob", addr[addr.Length - 1] !=
'/' ? addr : addr.Substring(0, addr.Length - 1));
                    string response = Utility.HttpResult.GetHttpRequest(url, sjd.ToString());
                    BarGraghDataJson result = Utility.JsonHelper.JsonDeserialize<BarGraghDataJson>(response);
                    if (result.IsOK)
                    {
                        BarGraghData data = result.Result;
                        _barGraghData = data;
                    }
                }
              
            }
            catch {}
        }

/// <summary>
        /// 把接收到的数据转换额外柱状图表所需要的数据, 绘制图表
        /// </summary>
        private void ToLineGragh()
        {
            ChartControl chartControl = new ChartControl();
            if (_barGraghData != null)
            {
                DataTable table = new DataTable();
                //横坐标显示值
                table.Columns.Add("hName", typeof(string));
                //纵坐标显示值
                table.Columns.Add("value", typeof(int));
                for (int i = 0; i < _barGraghData.GWFLMC.Length; i++)
                {
                    DataRow row = table.NewRow();
                    row["hName"] = _barGraghData.GWFLMC[i];
                    row["value"] = _barGraghData.GWSL[i];
                    table.Rows.Add(row);
                }
                //动态生成一个柱状图表,调用下面的静态方法
                chartControl = ToBarGraph.GetChartControl("", 0, table, "hName", "hName", "value");
            }
            //纵坐标标题
            chartControl.Dock = DockStyle.Fill;
            this.panel1.Controls.Add(chartControl);
            //X轴刻度间隔设置
            XYDiagram xydiagram = (XYDiagram)chartControl.Diagram;
            xydiagram.AxisX.MinorCount = 1;
            //小刻度是否显示
            xydiagram.AxisX.Tickmarks.Visible = false;
            xydiagram.AxisX.Range.MinValueInternal = -0.5D;
        }
    }

/// <summary>
    /// 热门岗位信息监测菜单
    /// </summary>
    public class HotjobMenu : BtnMenuBase
    {
        public override UserControl GetEditControl()
        {
            return new HotJobInfo();
        }
    }

/// <summary>
    /// 生成柱状图类
    /// </summary>
    public static class ToBarGraph
    {
        /// 获取图表
        /// </summary>
        /// <param name="titleName">图表名称</param>
        /// <param name="viewType">图表类型</param>
        /// <param name="dataSourse">数据源</param>
        /// <param name="textField1">显示文字字段</param>
        /// <param name="textField2">横坐标显示的文字字段</param>
        /// <param name="valueField">显示数值字段</param>
        /// <returns></returns>
        public static ChartControl GetChartControl(string titleName,
ViewType viewType, DataTable dataSourse, string textField1, string
textField2, string valueField)
        {
            ChartControl _ChartControl = new ChartControl();
            if (dataSourse == null || textField1 == "" || textField2 == "" || valueField == "")
            {
                return _ChartControl;
            }
            List<string> listTitle = new List<string>();
            foreach (DataRow item in dataSourse.Rows)
            {
                string title = item[textField1].ToString();
                if (listTitle.Contains(title))
                {
                    continue;
                }
                else
                {
                    listTitle.Add(title);
                    DataView dv = dataSourse.AsDataView();
                    dv.RowFilter = string.Format(" {0}='{1}' ", textField1, title);
                    DataTable dt = dv.ToTable();
                    // 柱状图里的第一个柱
                    Series Series1 = new Series(title, viewType);

Series1.ArgumentScaleType = ScaleType.Qualitative;
                    Series1.PointOptions.PointView = PointView.ArgumentAndValues;//显示表示的信息和数据
                    Series1.PointOptions.ValueNumericOptions.Precision = 0;
                    Series1.DataSource = dt;
                    //柱状图柱子的宽度设置
                    BarSeriesView bsv = (BarSeriesView)Series1.View;
                    bsv.BarWidth = 7;

// 以哪个字段进行显示
                    Series1.ArgumentDataMember = textField2;
                    Series1.ValueScaleType = ScaleType.Numerical;

// 柱状图里的柱的取值字段
                    Series1.ValueDataMembers.AddRange(new string[] { valueField });
                    Series1.LegendText = title;
                    _ChartControl.Series.Add(Series1);
                }
            }
            return _ChartControl;
        }

}

DevExpress ChartControl 柱状图的使用【转】的更多相关文章

  1. Devexpress ChartControl 柱状图简单例子

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

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

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

  3. [DevExpress]ChartControl之柱状图示例

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

  4. DevExpress中ChartControl柱状图(Bar)用法

    我的数据 代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 chartControl1.Series.Clear(); ...

  5. WPF DevExpress ChartControl使用之XYDiagram

    WPF使用Dev和WinForm有许多不同,相对而言,WPF要更简单和炫酷一点,我只做了一点基本的功能,没有仔细的研究,这里只介绍一下WPF Dev ChartControl绘制XYDiagram的基 ...

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

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

  7. [DevExpress]ChartControl之SeriesTemplate示例

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

  8. 初识Devexpress ChartControl 之 动态添加stepline及TextAnnotation

    最近在用devexpress 第三方软件做项目. devexpress 的控件使用简单.功能强大.类型丰富.界面优美.扩展性强.今天主要是动态生成了一条StepLine.生成后的效果(能力不强,所以做 ...

  9. DevExpress ChartControl 设置它的标题

    private void SetHZTitle(ref ChartControl chartControl, string HTitle) { chartControl.Titles.Clear(); ...

随机推荐

  1. ViewPager 无限循环

    Overview 我们在使用ViewPager来制作图片轮播的时候,常常为ViewPager不能一直无限循环的问题所苦恼.对于这个问题,目前从网上找到了两个思路来解决: 将 ViewPager 的Co ...

  2. BZOJ.4516.[SDOI2016]生成魔咒(后缀自动机 map)

    题目链接 后缀数组做法见这. 直接SAM+map.对于每个节点其产生的不同子串数为len[i]-len[fa[i]]. //15932kb 676ms #include <map> #in ...

  3. [POI2013]Usuwanka

    [POI2013]Usuwanka 题目大意: 一排\(n\)个球,有黑白两种颜色.每取走一个球会在原位置放一个水晶球.求构造一种取球方案,满足: 每次取走\(k\)个白球和\(1\)个黑球: 一次取 ...

  4. 模板 倍增维护RMQ

    倍增维护RMQ,nlogn预处理,O(1)查询 #include<bits/stdc++.h> using namespace std; const int maxn = 1e5+7; s ...

  5. Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary 并查集

    D. Mahmoud and a Dictionary 题目连接: http://codeforces.com/contest/766/problem/D Description Mahmoud wa ...

  6. 51Nod 1092 回文字符串(LCS + dp)

    51Nod 1092 数据结构暑假作业上出现的一题,学习了一下相关算法之后,找到了oj测试能AC. 1.回文串是一种中心对称的结构,这道题可以转变为求最长回文子序列长度的题目.(子序列:可以不连续) ...

  7. HDU 4122 Alice's mooncake shop (RMQ)

    Alice's mooncake shop Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. stm32的swd接口的烧写协议是否公开的呢?

    stm32的swd接口的烧写协议是否公开的呢? 需要用一台好的示波器来抓才能有足够的存储深度,保证你能够过滤掉那个该死的50clock. 按照Arm的手册,每次转换发送方都需要一个TNR---但是我观 ...

  9. PHP-FPM 不完全指南

    fpm工作流程 fpm全名是FastCGI进程管理器(FastCGI是啥?了解下cgi和fastcgi). fpm启动后会先读php.ini,然后再读相应的conf配置文件,conf配置可以覆盖php ...

  10. jQuery $('div>ul') $('div ul'

    $('div>ul')是<div>的直接后代里找<ul>: 而$('div ul')是在<div>的所有后代里找<ul>.