1.ChartAreas属性

ChartAreas属性指绘图区,一个控件可以有多个绘图区,比如我要在同一个控件内显示饼图和柱状图,肯定不能放在同一个ChartAreas区域内,应该在同一个Chart控件里增加两个ChartAreas并分别绑定Series对象。所以ChartAreas属性对应的是一个集合。

2.Series属性

Series属性就是各种图表的图形啦,比如我们要显示某月的天气变化,那么应该有这样两组数据,一组是天数,一组是每天对应的温度值,同时绑定到Series对象中,再将Series对象Add()到Chart控件的Series属性里即可。为了横向比较,例如我要看本月与上月的天气曲线变化图,并同时显示在同一个ChartAreas中,那该怎么办呢?很简单,再实例一个Series对象,将上月的天数数组与温度值数组绑定到一个新的Series2实例中,再将Series2实例Add()到Chart控件的Series属性里,此时,Chart控件的第一个绘图区ChartArea里就会有两条曲线。

3.Legends属性

Legend就是指一个图标的图例,当一个Series属性有多个Series时,或是一个Series有几组数据时,为了区分各自的颜色,通常每个Serie对象一种颜色,这就需要用到图例来指明哪个颜色的代表的是什么数据。

代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;namespace Chart_之雷达图
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){string[] x = new string[] { "成都大队", "广东大队", "广西大队", "云南大队", "上海大队", "苏州大队", "深圳大队", "北京大队", "湖北大队", "湖南大队", "重庆大队", "辽宁大队" };double[] y = new double[] { 589, 598, 445, 654, 884, 457, 941, 574, 745, 854, 684, 257 };string[] z = new string[] { "", "", "", "", "", "", "", "", "", "", "", "" };string[] a = new string[] { "成都大队", "广东大队", "广西大队", "云南大队", "上海大队" };double[] b = new double[] { 541, 574, 345, 854, 257 };#region 雷达图// //标题chart1.Titles.Add("消费行为TOP5");chart1.Titles[0].ForeColor = Color.Blue;chart1.Titles[0].Font = new Font("微软雅黑", 12f, FontStyle.Regular);chart1.Titles[0].Alignment = ContentAlignment.TopCenter;chart1.Titles.Add("合计:25412 宗 ");chart1.Titles[1].ForeColor = Color.Blue;chart1.Titles[1].Font = new Font("微软雅黑", 8f, FontStyle.Regular);chart1.Titles[1].Alignment = ContentAlignment.TopRight;//控件背景chart1.BackColor = Color.Transparent;chart1.ChartAreas[0].BackColor = Color.Transparent;chart1.ChartAreas[0].BorderColor = Color.Transparent;//X轴标签间距chart1.ChartAreas[0].AxisX.Interval = 1;chart1.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;chart1.ChartAreas[0].AxisX.LabelStyle.Angle = -45;chart1.ChartAreas[0].AxisX.TitleFont = new Font("微软雅黑", 14f, FontStyle.Regular);chart1.ChartAreas[0].AxisX.TitleForeColor = Color.Blue;//X坐标轴颜色chart1.ChartAreas[0].AxisX.LineColor = ColorTranslator.FromHtml("#38587a"); ;chart1.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Blue;chart1.ChartAreas[0].AxisX.LabelStyle.Font = new Font("微软雅黑", 10f, FontStyle.Regular);//X坐标轴标题//chart1.ChartAreas[0].AxisX.Title = "数量(宗)";//chart1.ChartAreas[0].AxisX.TitleFont = new Font("微软雅黑", 10f, FontStyle.Regular);//chart1.ChartAreas[0].AxisX.TitleForeColor = Color.White;//chart1.ChartAreas[0].AxisX.TextOrientation = TextOrientation.Auto;//chart1.ChartAreas[0].AxisX.ToolTip = "数量(宗)";//X轴网络线条chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = true;chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");//Y坐标轴颜色chart1.ChartAreas[0].AxisY.LineColor = ColorTranslator.FromHtml("#38587a");chart1.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Blue;chart1.ChartAreas[0].AxisY.LabelStyle.Font = new Font("微软雅黑", 10f, FontStyle.Regular);//Y坐标轴标题//chart1.ChartAreas[0].AxisY.Title = "数量(宗)";//chart1.ChartAreas[0].AxisY.TitleFont = new Font("微软雅黑", 10f, FontStyle.Regular);//chart1.ChartAreas[0].AxisY.TitleForeColor = Color.White;//chart1.ChartAreas[0].AxisY.TextOrientation = TextOrientation.Auto;//chart1.ChartAreas[0].AxisY.ToolTip = "数量(宗)";//Y轴网格线条chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = true;chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");chart1.ChartAreas[0].AxisY2.LineColor = Color.Transparent;chart1.ChartAreas[0].AxisX.IsMarginVisible = false;chart1.ChartAreas[0].Area3DStyle.Enable3D = true;chart1.ChartAreas[0].AxisX.IsInterlaced = false;chart1.ChartAreas[0].AxisX.IsMarginVisible = false;//刻度线chart1.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;//cht4.ChartAreas[0].AxisX.MajorGrid.Enabled = false;//cht4.ChartAreas[0].AxisY.MajorGrid.Enabled = false;//cht4.ChartAreas[0].AxisX.MajorTickMark.Enabled = false;chart1.ChartAreas[0].AxisY.LabelStyle.Enabled = false;//背景渐变chart1.ChartAreas[0].BackGradientStyle = GradientStyle.None;//chart1.ChartAreas[0].AxisX2.InterlacedColor = Color.Red;//chart1.ChartAreas[0].AxisY2.InterlacedColor = Color.Red;//chart1.ChartAreas[0].BorderWidth = 0;//chart1.ChartAreas[0].BackSecondaryColor = Color.Red;//chart1.ChartAreas[0].BackImageTransparentColor = Color.Red;//chart1.ChartAreas[0].AxisX.InterlacedColor = Color.Red;//chart1.ChartAreas[0].AxisX.LineColor = Color.Red;//chart1.ChartAreas[0].AxisX2.LineColor = Color.Red;//chart1.ChartAreas[0].AxisX2.MajorGrid.LineColor = Color.Red;//chart1.ChartAreas[0].AxisX2.MajorTickMark.LineColor = Color.Red;//chart1.ChartAreas[0].AxisX2.MinorTickMark.LineColor = Color.Red;//chart1.ChartAreas[0].AxisY.InterlacedColor = Color.Red;//chart1.ChartAreas[0].AxisY.LineColor = Color.Red;//chart1.ChartAreas[0].AxisY2.InterlacedColor = Color.Red;//chart1.ChartAreas[0].AxisY2.LineColor = Color.Red;//chart1.ChartAreas[0].AxisY2.MajorGrid.LineColor = Color.Red;//chart1.ChartAreas[0].AxisY2.MajorTickMark.LineColor = Color.Red;//chart1.ChartAreas[0].AxisY2.MinorTickMark.LineColor = Color.Red;//图例样式Legend legend4 = new Legend();legend4.Title = "图例";legend4.TitleBackColor = Color.Transparent;legend4.BackColor = Color.Transparent;legend4.TitleForeColor = Color.Blue;legend4.TitleFont = new Font("微软雅黑", 10f, FontStyle.Regular);legend4.Font = new Font("微软雅黑", 8f, FontStyle.Regular);legend4.ForeColor = Color.Blue;chart1.Legends.Add(legend4);chart1.Legends[0].Position.Auto = true;//Series1chart1.Series[0].XValueType = ChartValueType.String;chart1.Series[0].Label = "#VAL";chart1.Series[0].LabelForeColor = Color.Blue;chart1.Series[0].ToolTip = "#LEGENDTEXT:#VAL(宗)";chart1.Series[0].ChartType = SeriesChartType.Radar;chart1.Series[0]["RadarDrawingStyle"] = "Line";chart1.Series[0].LegendText = "2019年";chart1.Series[0].IsValueShownAsLabel = true;//Series2chart1.Series.Add(new Series("Series2"));chart1.Series[1].Label = "#VAL";chart1.Series[1].LabelForeColor = Color.Blue;chart1.Series[1].ToolTip = "#LEGENDTEXT:#VAL(宗)";chart1.Series[1].ChartType = SeriesChartType.Radar;chart1.Series[1]["RadarDrawingStyle"] = "Line";chart1.Series[1].LegendText = "2020年";chart1.Series[1].IsValueShownAsLabel = true;//Series3chart1.Series.Add(new Series("Series3"));chart1.Series[2].Label = "#VAL";chart1.Series[2].LabelForeColor = Color.Blue;chart1.Series[2].ToolTip = "#LEGENDTEXT:#VAL(宗)";chart1.Series[2].ChartType = SeriesChartType.Radar;chart1.Series[2]["RadarDrawingStyle"] = "Line";chart1.Series[2].LegendText = "2021年";chart1.Series[2].IsValueShownAsLabel = true;double[] yValues = { 65.62, 75.54, 60.45, 34.73, 85.42, 55.9, 63.6, 55.2, 77.1 };string[] xValues = { "France", "Canada", "Germany", "USA", "Italy", "Spain", "Russia", "Sweden", "Japan" };//Seris2  double[] y2 = { 45.62, 65.54, 70.45, 84.73, 35.42, 55.9, 63.6 };double[] y3 = { 88.62, 35.54, 52.45, 45.73, 88.42, 14.9, 33.6 };this.chart1.Series[0].Points.DataBindXY(xValues, yValues);this.chart1.Series[1].Points.DataBindY(y2);this.chart1.Series[2].Points.DataBindY(y3);//设置X轴显示间隔为1,X轴数据比较多的时候比较有用  chart1.ChartAreas[0].AxisX.LabelStyle.Interval = 1;//设置XY轴标题的名称所在位置位远  chart1.ChartAreas[0].AxisX.TitleAlignment = StringAlignment.Near;for (int i = 0; i < chart1.Series[2].Points.Count; i++){chart1.Series[2].Points[i].MarkerStyle = MarkerStyle.Circle;//设置折点的风格     chart1.Series[2].Points[i].MarkerColor = Color.Red;//设置seires中折点的颜色   //    cht4.Series[1].Points[i].MarkerStyle = MarkerStyle.Square;//设置折点的风格     //    cht4.Series[1].Points[i].MarkerColor = Color.Blue;//设置seires中折点的颜色  //    cht4.Series[2].Points[i].MarkerStyle = MarkerStyle.Square;//设置折点的风格     //    cht4.Series[2].Points[i].MarkerColor = Color.Green;//设置seires中折点的颜色  }for (int i = 0; i < chart1.Series.Count; i++){for (int j = 0; j < chart1.Series[i].Points.Count; j++){chart1.Series[i].Points[j].Label = " ";//cht4.Series[i].Points[j].LabelToolTip = "string.Empty";}}//chart1.ImageType = ChartImageType.Jpeg;//反锯齿  chart1.AntiAliasing = AntiAliasingStyles.All;//调色板 磨沙:SemiTransparent  chart1.Palette = ChartColorPalette.BrightPastel;chart1.Series[0].ChartType = SeriesChartType.Radar;chart1.Series[1].ChartType = SeriesChartType.Radar;chart1.Series[2].ChartType = SeriesChartType.Radar;chart1.Width = 500;chart1.Height = 350;#endregion/* #VALX      显示当前图例的X轴的对应文本(或数据) #VAL, #VALY,  显示当前图例的Y轴的对应文本(或数据) #VALY2, #VALY3, 显示当前图例的辅助Y轴的对应文本(或数据) #SER:      显示当前图例的名称 #LABEL       显示当前图例的标签文本 #INDEX      显示当前图例的索引 #PERCENT       显示当前图例的所占的百分比 #TOTAL      总数量 #LEGENDTEXT      图例文本 */}}
}

C# Winform Chart控件用法6之雷达图相关推荐

  1. C# Winform Chart控件用法5之Bar图

    1.ChartAreas属性 ChartAreas属性指绘图区,一个控件可以有多个绘图区,比如我要在同一个控件内显示饼图和柱状图,肯定不能放在同一个ChartAreas区域内,应该在同一个Chart控 ...

  2. C# Winform Chart控件用法1

    1.Chart控件五大核心" 图表属性 "--它们均是" 集合 " ChartAreas属性 Series属性 Legends属性 Titles 属性 Anno ...

  3. C# Winform Chart控件用法4之饼状图

    1.拖chart控件在新建的窗口,命名chart1 2.源代码 using System; using System.Collections.Generic; using System.Compone ...

  4. C# Winform Chart控件用法3 柱状图

    效果图如下: 1.拖chart控件在新建的窗口,命名chart1 2.源代码 using System; using System.Collections.Generic; using System. ...

  5. winform chart控件设置

    winform chart控件设置//seriesX.MarkerColor = Color.Green;//设置点的大小//seriesX.MarkerSize = 5;//seriesX.Mark ...

  6. 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)...

    (一).说明 功能类似Windows 操作系统自带的记事本.  一个WinForm记事本程序(包含主/下拉/弹出 菜单/打开保存对话框等控件用法以及记事本菜单事件的具体代码) (二).图片示例 (三) ...

  7. C# WinForm开发系列之c# 通过.net自带的chart控件绘制饼图,柱形图和折线图的基础使用和扩展

    一.需要实现的目标是: 1.将数据绑定到pie的后台数据中,自动生成饼图. 2.生成的饼图有详细文字的说明. 1.设置chart1的属性Legends中默认的Legend1的Enable为false: ...

  8. 基于Winform的Chart控件的简单使用(Chart控件中的条形统计图、折线统计图、扇形统计图的简单使用)

    Chart控件集成了颇多的统计图模型,拿来即用的理念大大节省了开发的时间.下面演示最常见的三种统计图模型的使用. 效果展示: C#代码: using System; using System.Coll ...

  9. C#学习(十五)——窗体控件用法大全

    C#控件及常用设计整理 1.窗体 1.1.常用属性** (1)Name属性:用来获取或设置窗体的名称,在应用程序中可通过Name属性来引用窗体. (2) WindowState属性: 用来获取或设置窗 ...

最新文章

  1. python零基础看什么视频和书籍-资料│最适合大学生零基础学的Python视频+电子书...
  2. 刘歧:让人生不留遗憾
  3. Angular jasmine TestBed.configureTestingModule的工作原理
  4. Unity优化之GC——合理优化Unity的GC (难度3 推荐5)
  5. 网格布局之网格元素放置算法
  6. Spring MVC DispatcherServlet介绍
  7. 关于python字符编码以下选项中描述错误的是_关于import引用,以下选项中描述错误的是...
  8. 再获数千万融资,湃方科技将工业智联革命进行到底
  9. TCP/IP模型背后的内涵(二)
  10. 概率论与数理统计(陈希孺)笔记2.2
  11. 转:管理欲望:领导者的自我觉察与突破
  12. [转]中国象棋谚语大全
  13. request请求 下载附件
  14. html 下拉框树,下拉框显示树形菜单
  15. NLP之NER:商品标题属性识别探索与实践
  16. 给键盘加上音效(机械键盘音效)
  17. 半导体上下游供应商汇总(值得收藏)
  18. 总结下linux中一些入门级shell编程实例
  19. 安卓一键清理内存_一款强大的安卓手机内存清理软件吃掉内存
  20. Android多个fragment懒加载的坑(卡顿)

热门文章

  1. [Linux] 使用移动硬盘安装ubuntu17.10记录
  2. Prometheus入门教程
  3. Oracle 交集/并集/差集(intersect/union/minus)
  4. vim 退出命令(保存、放弃保存)
  5. Win10解决右下角“拼”字图标
  6. 美国埃博拉疫苗从何而来?
  7. 验证工程师如何才能脱颖而出?
  8. 浏览器点击URL的响应过程
  9. 忆2018,展2019
  10. NAACL 2019 字词表示学习分析