Dev之ChartControl控件(二)— 绘制多重坐标图形
有时针对一个ChartControl控件可能要设置多个Y轴,进行显示:
以下举个例子:如在一个Chart中显示多个指标项如图:

首先,读取数据,并对左边的Y轴最大和最小值进行设定
IndexSeriesControler indexControl = new IndexSeriesControler();
IEnumerable<IndexModel> ieModel= indexControl.GetDate(dateB,dateE,indexName);//读取的数据集
decimal max= ieModel.Max(x => x.IndexValue);
decimal min = ieModel.Min(x => x.IndexValue);
其次,生成Series,并添加到charControl控件;
Series series = new Series(indexName, ViewType.Spline);
if (num != )
{
lstSeries.Add(series);
} foreach (IndexModel model in ieModel)
{
series.Points.Add(new SeriesPoint(model.PublishDate, new double[] { (double)model.IndexValue }));
} series.View = splineSeriesView1; this.chartControl.Series.Add(series); this.chartControl.Legend.Visible = false;
再次,创建图标的第二坐标;
效果如图:

public void GetAxisY()
{
for (int i = ; i < lstSeries.Count; i++)
{
lstSeries[i].View.Color = lstColor[i];
CreateAxisY(lstSeries[i]);
}
} /// <summary>
/// 创建图表的第二坐标系
/// </summary>
/// <param name="series">Series对象</param>
/// <returns></returns>
private SecondaryAxisY CreateAxisY(Series series)
{
SecondaryAxisY myAxis = new SecondaryAxisY(series.Name);
((XYDiagram)chartControl.Diagram).SecondaryAxesY.Add(myAxis);
((LineSeriesView)series.View).AxisY = myAxis;
myAxis.Title.Text = series.Name;
myAxis.Title.Alignment = StringAlignment.Far; //顶部对齐
myAxis.Title.Visible = true; //显示标题
myAxis.Title.Font = new Font("宋体", 9.0f); Color color = series.View.Color;//设置坐标的颜色和图表线条颜色一致 myAxis.Title.TextColor = color;
myAxis.Label.TextColor = color;
myAxis.Color = color; return myAxis;
}
完整代码如下:
public partial class ChartControlExtension : UserControl
{
public ChartControlExtension()
{
InitializeComponent();
ChartTitle chartTitle=new ChartTitle();
chartTitle.Text="新干线";
chartTitle.TextColor=System.Drawing.Color.Black;
this.chartControl.Titles.Add(chartTitle);
lstColor.Add(Color.Red);
lstColor.Add(Color.Black);
lstColor.Add(Color.Blue);
lstColor.Add(Color.Brown);
}
public bool IsRange { set; get; }
public List<Series> lstSeries = new List<Series>();
public List<Color> lstColor = new List<Color>();
int num = ;
public void GetDate(DateTime dateB, DateTime dateE, string indexName)
{
IndexSeriesControler indexControl = new IndexSeriesControler();
IEnumerable<IndexModel> ieModel= indexControl.GetDate(dateB,dateE,indexName);
decimal max= ieModel.Max(x => x.IndexValue);
decimal min = ieModel.Min(x => x.IndexValue);
// this.chartControl.Series.Clear(); Series series = new Series(indexName, ViewType.Spline);
if (num != )
{
lstSeries.Add(series);
} foreach (IndexModel model in ieModel)
{
series.Points.Add(new SeriesPoint(model.PublishDate, new double[] { (double)model.IndexValue }));
} this.chartControl.Series.Add(series);
this.chartControl.Legend.Visible = false;
//this.chartControl.cut
if (num == )
{
XYDiagram diag = (XYDiagram)this.chartControl.Diagram;
diag.AxisY.VisualRange.MaxValue = max;
diag.AxisY.VisualRange.MinValue = min-;
} //this.IsRange = true;
num++; } public void GetAxisY()
{
for (int i = ; i < lstSeries.Count; i++)
{
lstSeries[i].View.Color = lstColor[i];
CreateAxisY(lstSeries[i]);
}
} /// <summary>
/// 创建图表的第二坐标系
/// </summary>
/// <param name="series">Series对象</param>
/// <returns></returns>
private SecondaryAxisY CreateAxisY(Series series)
{
SecondaryAxisY myAxis = new SecondaryAxisY(series.Name);
((XYDiagram)chartControl.Diagram).SecondaryAxesY.Add(myAxis);
((LineSeriesView)series.View).AxisY = myAxis;
myAxis.Title.Text = series.Name;
myAxis.Title.Alignment = StringAlignment.Far; //顶部对齐
myAxis.Title.Visible = true; //显示标题
myAxis.Title.Font = new Font("宋体", 9.0f); Color color = series.View.Color;//设置坐标的颜色和图表线条颜色一致 myAxis.Title.TextColor = color;
myAxis.Label.TextColor = color;
myAxis.Color = color; return myAxis;
}
}
调用方法:
private void tolBtnSearch_Click(object sender, EventArgs e)
{
chartControlExtension1.GetDate(datPBegin.Value,datPEnd.Value,"铁矿石指数");
chartControlExtension1.GetDate(datPBegin.Value, datPEnd.Value, "钢材指数");
chartControlExtension1.GetDate(datPBegin.Value, datPEnd.Value, "铁矿指数");
chartControlExtension1.GetDate(datPBegin.Value, datPEnd.Value, "焦炭指数");
chartControlExtension1.GetAxisY(); }
其打印方法可用:
this.chartControl.ShowPrintPreview(DevExpress.XtraCharts.Printing.PrintSizeMode.Zoom);
Dev之ChartControl控件(二)— 绘制多重坐标图形的更多相关文章
- DevExpress控件使用之多重坐标图形的绘制 z
有时候,基于对一些年份.月份的统计,需要集成多个数值指标进行分析,因此就需要把多种数据放到一个图形里面展现,也成为多重坐标轴,多重坐标轴可以是多个X轴,也可以是Y轴,它们的处理方式类似.本文通过一个例 ...
- Dev之ChartControl控件(一)
ChartControl控件主要包括Chart Title,Legend,Annotations,Diagram,Series五部分:如图: 1. 用RangeControl控件控制ChartCon ...
- DevExpress使用之ChartControl控件绘制图表(多坐标折线图、柱状图、饼状图)
最近因为公司项目需要用到WinForm的DecExpress控件,在这里把一些使用方法总结一下. DevExpress中有一个专门用来绘制图表的插件ChartControl,可以绘制折线图.饼状图.柱 ...
- WinForm DevExpress使用之ChartControl控件绘制图表一——基础
最近因为公司项目需要用到WinForm的DecExpress控件,在这里把一些使用方法总结一下. DevExpress中有一个专门用来绘制图表的插件ChartControl,可以绘制折线图.饼状图.柱 ...
- QRowTable表格控件(二)-红涨绿跌
目录 一.开心一刻 二.概述 三.效果展示 四.任务需求 五.指定列排序 六.排序 七.列对其方式 八.相关文章 原文链接:QRowTable表格控件(二)-红涨绿跌 一.开心一刻 一天,五娃和六娃去 ...
- 玩转控件:对Dev中GridControl控件的封装和扩展
又是一年清明节至,细雨绵绵犹如泪光,树叶随风摆动.... 转眼间,一年又过去了三分之一,疫情的严峻让不少企业就跟清明时节的树叶一样,摇摇欲坠.裁员的裁员,降薪的降薪,996的996~~说起来都是泪,以 ...
- Windows高DPI系列控件(二) - 柱状图
目录 一.QCP 二.效果展示 三.高DPI适配 1.自定义柱状图 2.新的柱状图 3.测试代码 四.相关文章 原文链接:Windows高DPI系列控件(二) - 柱状图 一.QCP QCP全称QCu ...
- WPF 截图控件之绘制箭头(五)「仿微信」
前言 接着上周写的截图控件继续更新 绘制箭头. 1.WPF实现截屏「仿微信」 2.WPF 实现截屏控件之移动(二)「仿微信」 3.WPF 截图控件之伸缩(三) 「仿微信」 4.WPF 截图控件之绘制方 ...
- 在Image控件中绘制文字
//Canvas 在Image控件中绘制文字 procedure TForm1.Button1Click(Sender: TObject);begin image1.Canvas.Font.Size ...
随机推荐
- XP 右键扩展设置 1.0 免费绿色版
软件名称: xp右键扩展设置软件 1.0 免费绿色版软件语言: 简体中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 / WinXP / Win2008软件大小: 57 ...
- SCALA STEP BY STEP
http://www.artima.com/scalazine/articles/steps.html http://hongjiang.info/scala/
- Strusts2--课程笔记5
数据验证: 输入验证分为客户端验证与服务器端验证.客户端验证主要通过JavaScript脚本进行,而服务器端验证主要是通过Java代码进行验证. 分为以下四种情况: (1)手工编写代码,对所有Ac ...
- 编译OpenGL代码时发生 Inconsistency detected by ld.so: dl-version.c: 224: _dl_check_map_versions: Assertion `needed != ((void *)0)' failed! 错误的解决方案
注:本解决方案适用于使用N卡的PC 出现该错误 , 一般是由于开源的nouveau驱动和Nvidia专有驱动冲突导致的 .在解决该问题时 , 尝试过卸载 N 卡专有驱动 , 仅使用开源nouveau驱 ...
- URL scheme添加以及查找方式
2.1.1 添加URL Types URL Scheme是通过系统找到并跳转对应app的一类设置,通过向项目中的info.plist文件中加入URL types可使用第三方平台所注册的appkey信 ...
- 《C++ Primer》之面向对象编程(四)
纯虚函数 在前面所提到过的 Disc_item 类提出了一个有趣的问题:该类从 Item_base 继承了 net_price 函数但没有重定义该函数.因为对 Disc_item 类而言没有可以给予该 ...
- Windows线程同步(下)
线程同步三:事件 CreateEvent:Creates or opens a named or unnamed event object. HANDLE WINAPI CreateEvent( _I ...
- OA系统出现窗口拦截的解决办法
我们使用oa时候,有时候会出现“你打开了窗口拦截功能”.如图 出现窗口被拦截主要有三种情况,分别是IE浏览器本身拦截功能.第三方插件(如百度工具栏.搜搜工具栏.谷歌工具栏等).第三方浏览器拦截功能(如 ...
- 第三十四节,pickle数据类型转换二进制字节码模块
在使用pickle模块时需要先 import pickle 引入模块 pickle.dumps()模块函数 功能:将python各种类型的数据转换成计算机识别的二进制字节码[有参] 使用方法:pick ...
- MVC中用 BundleCollection 压缩CSS时图片路径问题
MVC中有个专门提供JS和CSS压缩的类,BundleCollection,其实这个类也可以在asp.net中用, 关于BundleCollection类的详细推荐个地址:http://www.cnb ...