c# Winform Chart入门
额外参考链接:http://www.cnblogs.com/greenerycn/archive/2008/10/27/microsoft-chart.html
winform 仪表盘相关下载链接://download.csdn.net/download/floweroflvoe/10432601?utm_source=bbsseo
首先添加引用System.Windows.Forms.DataVisualization,添加引用后,工具面板上将在数据中显示Chart,可直接拖拽到界面上。
代码中添加UsingSystem.Windows.Forms.DataVisualization.Charting;

1. 当拖拽Chart到界面上时,一般来说Chart及其ChartAreas、Legend部分的背景为白色,我们可以分别通过各自的BackColor设置为透明或其他颜色。
通过设置Series的ChartType属性来选择图表类型,一般常用:折线Line,柱状图Column,饼状图Pie,雷达图Redar等等。
2. 设置ChartAreas属性
ct.ChartAreas.Add(new ChartArea() { Name = "ca1" }); //背景框
ct.ChartAreas[0].Axes[0].MajorGrid.Enabled = false; //X轴上网格
ct.ChartAreas[0].Axes[1].MajorGrid.Enabled = false; //y轴上网格
ct.ChartAreas[0].Axes[0].MajorGrid.LineDashStyle = ChartDashStyle.Dash; //网格类型 短横线
ct.ChartAreas[0].Axes[0].MajorGrid.LineColor = Color.Gray;
ct.ChartAreas[0].Axes[0].MajorTickMark.Enabled = false; // x轴上突出的小点
ct.ChartAreas[0].Axes[1].MajorTickMark.Enabled = false; //
ct.ChartAreas[0].Axes[1].IsInterlaced = true; //显示交错带
ct.ChartAreas[0].Axes[0].LabelStyle.Format = "#年"; //设置X轴显示样式
ct.ChartAreas[0].Axes[1].MajorGrid.LineDashStyle = ChartDashStyle.Dash; //网格类型 短横线
ct.ChartAreas[0].Axes[1].MajorGrid.LineColor = Color.Blue;
ct.ChartAreas[0].Axes[1].MajorGrid.LineWidth = 3;
ct.ChartAreas[0].BackColor = System.Drawing.Color.Transparent; //设置区域内背景透明
3. 设置值Series
//添加的两组Test数据
List<int> txData2 = new List<int>() { 2011, 2012, 2013, 2014, 2015, 2016 };
List<int> tyData2 = new List<int>() { 9, 6, 7, 4, 5, 4 };
List<int> txData3 = new List<int>() { 2012 };
List<int> tyData3 = new List<int>() { 7 };
ct.Series.Add(new Series()); //添加一个图表序列
// ct.Series[0].XValueType = ChartValueType.String; //设置X轴上的值类型
ct.Series[0].Label = "#VAL"; //设置显示X Y的值
ct.Series[0].ToolTip = "#VALX年\r#VAL"; //鼠标移动到对应点显示数值
ct.Series[0].ChartArea = ct.ChartAreas[0].Name; //设置图表背景框ChartArea
ct.Series[0].ChartType = SeriesChartType.Line; //图类型(折线)
ct.Series[0].Points.DataBindXY(txData2, tyData2); //添加数据
//折线段配置
ct.Series[0].Color = Color.Red; //线条颜色
ct.Series[0].BorderWidth = 3; //线条粗细
ct.Series[0].MarkerBorderColor = Color.Red; //标记点边框颜色
ct.Series[0].MarkerBorderWidth = 3; //标记点边框大小
ct.Series[0].MarkerColor = Color.Red; //标记点中心颜色
ct.Series[0].MarkerSize = 5; //标记点大小
ct.Series[0].MarkerStyle = MarkerStyle.Circle; //标记点类型
ct.Series.Add(new Series()); //添加一个图表序列
ct.Series[1].Label = "#VAL"; //设置显示X Y的值
ct.Series[1].ToolTip = "#VALX年\r#VAL"; //鼠标移动到对应点显示数值
ct.Series[1].ChartArea = "ca1"; //选择显示的ChartArea ,如果和其他的Series选择是同一个ChartArea,则在同一个区域中显示对比
ct.Series[1].ChartType = SeriesChartType.Line; //图类型(折线)
ct.Series[1].Points.DataBindXY(txData3, tyData3); //添加数据
//折线段配置
ct.Series[1].Color = Color.Black; //线条颜色
ct.Series[1].BorderWidth = 3; //线条粗细
ct.Series[1].MarkerBorderColor = Color.Black; //标记点边框颜色
ct.Series[1].MarkerBorderWidth = 3; //标记点边框大小
ct.Series[1].MarkerColor = Color.Black; //标记点中心颜色
ct.Series[1].MarkerSize = 5; //标记点大小
ct.Series[1].MarkerStyle = MarkerStyle.Circle; //标记点类型
4.其他ChartType的特殊设置
//饼图说明设置,这用来设置饼图每一块的信息显示在什么地方
ct.Series[0]["PieLabelStyle"] = "Outside";//将文字移到外侧
ct.Series[0]["PieLineColor"] = "Black";//绘制黑色的连线。
//柱状图其他设置
ct.Series[0]["DrawingStyle"] = "Emboss"; //设置柱状平面形状
ct.Series[0]["PointWidth"] = "0.5"; //设置柱状大小
5. 几种ChartType展示
![]() |
![]() |
![]() |
![]() |
| 折线图-Line | 柱状图-Column | 饼状图-Pie | 雷达图-Redar |
![]() |
![]() |
![]() |
|
| Spline | Bar | Doughnut |
c# Winform Chart入门的更多相关文章
- c# winform Chart Pie 中若X轴数据为字符串时,#VALX取值为0
https://q.cnblogs.com/q/83848/ 在winform程序中用自带的Chart进行画图表时,若画饼图,其中X轴数据为字符串,这时候如果想设置Label值的格式为#VALX:#V ...
- Winform Chart
Chart图表解释说明: 第一步:使用VS创建Winform项目: 第二步:工具箱中拖入Chart控件: 第三步:所有控件拖入其他控件如下图所示: using System; using System ...
- WPFTookit Chart 入门
如何使用WPFToolKit Chart private void button1_Click(object sender, EventArgs e) { var s = new Series(); ...
- winform Chart控件 获取鼠标处坐标值方法
Chart控件本身功能强大,应用广泛,因此其属性.方法也很多.此处介绍在很多应用中需要查看鼠标位置处坐标值的一些方法 1,调用Chart事件 GetToolTip 利用ToolTipEventArg ...
- WPF 使用WinForm Chart控件
第一步: 页面 首先引用命名空间 xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFor ...
- 使用WinForm Chart控件 制作饼装,柱状,折线图
http://blog.csdn.net/dream2050csdn/article/details/53510340 chart控件的属性很多,主要用到Chart控件图表区域的属性有五个属性 1.A ...
- Winform开发入门集中培训系列文章
最近有个培训,写PPT不如写博客了,共享是程序猿的职业情操吧,因此,本人准备写一个Winform开发的系列文章,对于初级开发者来说,应该比较有用,写作当中不免错误或不成熟的地方,看到的朋友请留言指出, ...
- 【207】WinForm Chart类
目录: 在工具箱中找到 Chart 控件并使用 设置 Chart 属性 代码中设置属性 属性中设置属性 Chart 类说明 ChartAreas ChartAreaCollection 类 Chart ...
- C#的winform编程入门简单介绍
C#中事件.事件委托.事件的订阅 例子: using System.Timers; Timer t1 = new Timer(); t1.Tick += new EventHandler(XX); p ...
随机推荐
- GRU and LSTM
门控循环单元(GRU): 背景: 当时间步数较大或者时间步数较小的时候,循环神经网络的梯度较容易出现衰减或者爆炸.虽然裁剪梯度可以应对梯度爆炸, 但是无法解决梯度衰减的问题.正因为如此,循环神经网络在 ...
- kubernetes 开发 code-generator
主要参考项目 https://github.com/kubernetes/code-generator 1. git clone https://github.com/kubernetes/code- ...
- linux windows 格式化一块大于2 TiB硬盘
转自:https://help.aliyun.com/document_detail/34377.html?spm=a2c4g.11186623.2.10.17447386JrLBNR#concept ...
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application问题解决方案参考
错误信息:The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the ...
- 常用的tcpdump操作
tcpdump -i eth0 icmp and host 192.168.0.111 -nn -tttt 用ping检测网络情况时抓包,-nn 显示ip和端口而不是机器名和进程名,-tttt 显示详 ...
- 18B20驱动小经验
在写命令时P14拉高在最后 在读命令时P14在拉低后拉高
- MemoryStream生成Excel
public static MemoryStream ToExcel<T>(List<T> list, string filePath = null) { var memory ...
- Vue学习(一)Vue目录结构
安装教程网上一大把,可以自己搜索.记录下学习过程. 认识下Vue的目录结构,取自:https://www.cnblogs.com/dragonir/p/8711761.html vue 文件目录结构详 ...
- linux服务基础之http协议
URI:Uniform Resource Identifier URL: Uniform Resource Locator,用于描述某服务器某特定资源的位置 URN: Uniform Resource ...
- [FJOI2018]领导集团问题 mulitset合并
P4577 [FJOI2018]领导集团问题 链接 luogu bzoj 他是个重题 bzoj4919: [Lydsy1706月赛]大根堆 代码改改就过了 思路 求树上的lis,要好好读题目的!!! ...






