初识Devexpress ChartControl 之 动态添加stepline及TextAnnotation
最近在用devexpress 第三方软件做项目。
devexpress 的控件使用简单、功能强大、类型丰富、界面优美、扩展性强。今天主要是动态生成了一条StepLine。生成后的效果(能力不强,所以做的比较简单。):

首先,建立一个form(普通的或ribbonform均可),然后拖拽一个chartControl到form中。右键run warzid。然后将预设的线条删除(因为我们要动态添加)。
然后查看form代码。在构造函数中添加方法调用InitCharControl();
然后新建InitCharControl方法,此方法主要功能是生成stepline.
代码如下:

//init ChartControl1
//create dataTable
DataTable dt1 = new DataTable();
dt1.Columns.Add("count", typeof(long));
dt1.Columns.Add("step", typeof(string));
dt1.Columns.Add("pass", typeof(string));
for (int i = 1; i <= 4; i++)
{
DataRow dr = dt1.NewRow();
dr["count"] = i * 10;
dr["step"] = "step" + i;
dr["pass"] = "通过率:" + i * 10 + "%";
dt1.Rows.Add(dr);
}
//create new series
Series series2 = new Series();
StepLineSeriesView stepLine = new StepLineSeriesView();
stepLine.LineMarkerOptions.Kind = MarkerKind.Square;
stepLine.LineMarkerOptions.Size = 50;
series2.View = stepLine;
chartControl1.Series.Add(series2);
//datasource bind
chartControl1.Series[0].ArgumentDataMember = "step";
chartControl1.Series[0].ValueDataMembers.AddRange(new string[] { "count" });
chartControl1.DataSource = dt1;
int count=0;
foreach(SeriesPoint point in series2.Points )
{
SeriesPointAnchorPoint anchorPoint = new SeriesPointAnchorPoint();
anchorPoint.SeriesPoint = point;
TextAnnotation txtAnnotation = new TextAnnotation();
txtAnnotation.RuntimeRotation = true;
txtAnnotation.RuntimeResizing = true;
txtAnnotation.RuntimeMoving = true;
txtAnnotation.RuntimeAnchoring = true;
txtAnnotation.Text = dt1.Rows[count++]["pass"].ToString();
txtAnnotation.ShapePosition = new RelativePosition(319.97, -48);
txtAnnotation.AnchorPoint = anchorPoint;
chartControl1.AnnotationRepository.Add(txtAnnotation);
}

2.添加多条stepline
对于chartControl 只有以条数据显然是没有用的。因此可能会生成多条线,供对比用。
下面我们就来看看如何生成多条setpline(本例以两条为例)
其实从上例中可以看到如何把数据源绑定到一条setpline上,当绑定两条时原理是相同的但是在绑定时就需要将数据源绑定到指定名称或索引值的setpline上。
只需要将绑定语句改写为:
chartControl1.Series[lineName].DataSource = dt1;
以下是完整代码:

private void InitCharControl(string lineName)
{
//init ChartControl1 #region 手动添加节点、批注 #endregion
// get datatable
DataTable dt1 = InitDataTable(); //create new series
Series series2 = new Series(lineName,ViewType.StepLine);
StepLineSeriesView stepLine = new StepLineSeriesView();
stepLine.LineMarkerOptions.Kind = MarkerKind.Square;
stepLine.LineMarkerOptions.Size = 50;
series2.View = stepLine; chartControl1.Series.Add(series2); chartControl1.Series[lineName].ArgumentDataMember = "step";
chartControl1.Series[lineName].ValueDataMembers.AddRange(new string[] { "count" });
chartControl1.Series[lineName].DataSource = dt1;
int count = 0;
foreach (SeriesPoint point in chartControl1.Series[lineName].Points)
{ SeriesPointAnchorPoint anchorPoint = new SeriesPointAnchorPoint();
anchorPoint.SeriesPoint = point; TextAnnotation txtAnnotation = new TextAnnotation();
txtAnnotation.RuntimeRotation = true;
txtAnnotation.RuntimeResizing = true;
txtAnnotation.RuntimeMoving = true;
txtAnnotation.RuntimeAnchoring = true; txtAnnotation.Text = dt1.Rows[count++]["pass"].ToString();
txtAnnotation.ShapePosition = new RelativePosition(319.97, -48);
txtAnnotation.AnchorPoint = anchorPoint; chartControl1.AnnotationRepository.Add(txtAnnotation);
}
}

这样只需递归调用该方法并传递不同名字,就会生成不同的stepline啦,生成的线系统会自动用不同颜色进行区别,当然你也可以自己改造该函数在构造线时指定颜色,如果有隐藏数据需要绑定到节点上可以利用节点的tag属性进行绑定。
初识Devexpress ChartControl 之 动态添加stepline及TextAnnotation的更多相关文章
- DevExpress.XtraLayout.LayoutControl 动态添加控件
// Create an item within a specified group,// bound to a specified data field with the specified edi ...
- 关于devexpress报表XtraReport,动态修改报表样式(.repx格式),动态添加数据并使用的理解
一.基本概念: XtraReports 中的每个报表都由 XtraRepot 类的一个实例表示,或者由该类的子类来表示(这种情况更常见). 因此,每个报表都作为带区的容器使用,而每个带区中都包含报表控 ...
- DataGridview动态添加列
1.获取数据源(select * from table名称) 2.动态绑定数据源 private void GetTableInfo(DataTable dt) { listBh = new List ...
- js动态添加事件-事件委托
作者:白狼 出处:http://www.manks.top/javascript-dynamic-event.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给 ...
- 后台动态添加的button,如何触发button_click事件?
后台动态添加的button,需要在Page_Load或者Page_Init重新动态生成才能执行button_click public Panel GetContrlType() { Panel pan ...
- jquery动态添加的html,第三方插件无法生效的情况
今天一个问题纠结了半天,问题如下图 问题大致就是如上,新增的内容死活点不起,插件没有生效,在一个装逼前端群里面问,给我的答案是叫我去了解事件委托,了解一下事件冒泡!! 好吧,我一上午加半个下午的时间 ...
- 【Java EE 学习 75 下】【数据采集系统第七天】【二进制运算实现权限管理】【使用反射初始化权限表】【权限捕获拦截器动态添加权限】
一.使用反射动态添加权限 在该系统中,我使用struts2的时候非常规范,访问的Action的形式都是"ActionClassName_MethodName.action?参数列表" ...
- Hadoop学习笔记—13.分布式集群中节点的动态添加与下架
开篇:在本笔记系列的第一篇中,我们介绍了如何搭建伪分布与分布模式的Hadoop集群.现在,我们来了解一下在一个Hadoop分布式集群中,如何动态(不关机且正在运行的情况下)地添加一个Hadoop节点与 ...
- Net作业调度(五)—quartz.net动态添加job设计
介绍 在实际项目使用中quartz.net中,都希望有一个管理界面可以动态添加job,而避免每次都要上线发布. 也看到有园子的同学问过.这里就介绍下实现动态添加job的几种方式, 也是二次开发的核心模 ...
随机推荐
- Codeforces #345 Div.1
Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...
- 【UVA 10307 Killing Aliens in Borg Maze】最小生成树, kruscal, bfs
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20846 POJ 3026是同样的题,但是内存要求比较严格,并是没有 ...
- 关于各种排列(dfs)
代码一:数字有重复: #include <cstdio> ],arr[]={,,,}; void dfs(int v){ if(v >= n){ ;i<n;i++) print ...
- C++暂时对象
C++真正所谓的暂时对象是不可见的--不会在你的源码中出现.仅仅要你产生一个non-heap object而没有为它命名,便诞生了一个暂时对象.此等匿名对象通常发生于两种情况: 一是当隐式类型转换(i ...
- 在 Mac OS X Lion 下修改 Hosts 的四种方法
一名刚刚使用 Mac OS X Lion 系统的朋友问我怎么该系统下修改 Hosts 文件,说网上搜了很多办法都不管用,只要编辑 Hosts 文件就出现”你不是文件 hosts 的所有者,因此没有权限 ...
- css3 transiton
div { width:100px; height:100px; background:yellow; transition-property:width; transition-duration:1 ...
- adb server didn t ack failed to start daemon
关掉Ecilpse,打开cmd命令行 1)cd到sdk的platform-tools目录下, 2)执行 adb kill-server ,出现 server not runing 提示 3)执行 ...
- linux下Java环境的配置
linux下Java环境的配置 现在用linux的朋友越来越多了,前几天就有两个朋友问我linux下怎么配置java环境,我想还有很多朋友想了解学习这方面的东西,就写一个完全一点的linux java ...
- thbgm拆包【in progress】
曾经在网上找过但是没找到过....关于东方系列bgm的格式,最初以为是个加密格式,后来听说是多个wav堆到一块儿的.再后来查到有说可以用GoldWave开的.今天试了试成功了.接下来打算研究一下,不过 ...
- 远程连接mysql数据慢的问题
由于公司没有服务器,买的阿里云的服务器用于开发,所以就在本地连接服务器的mysql. 连接很慢,打开表也很慢,一开始没多想,以为是网络慢而已. 最近,开发经常要使用navicat连接数据库,实在是太慢 ...