当前位置:网站首页>C winfrom chart chart control bar chart and line chart
C winfrom chart chart control bar chart and line chart
2022-06-29 16:29:00 【Xiongsiyu】
Catalog
3、 ... and 、 Broken line diagram
effect



One 、 Reference resources
c# Chart Set the style - wenglabs - Blog Garden
Powerful Winform Chart Chart control instructions - Let's have a look
Two 、 Histogram
1. New projects
Create a new one .NET Framework Type of Winfrom project , Find... In the data Chart Control , Drag into the interface

as follows :

When dragging a control , There is a chart style by default , The actual operation is actually a blank

2. Change the chart style
stay Series here , Click the back of the set to three points

The corresponding name can be modified here , Add a button on the left here , You can add a set of histograms , If it's a line chart , Two wires .
Here you can change the style of the chart , For example, histogram , Broken line diagram

3. Data binding
There is no data in the chart at this time , You can add data by binding , as follows
private List<int> XList = new List<int>();
private List<int> YList = new List<int>();
private Random randoms = new Random();
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 6; i++)
{
XList.Add(i);
YList.Add(randoms.Next(10, 100));
}
chart1.Series["Series1"].Points.DataBindXY(XList, YList);
}After operation, it is as follows

There are two problems in the figure above ,
1. The bar graph does not show specific data , It is impossible to see how much the actual data is ,
2. The background grid is not removed , The style is ugly ,
You can solve these two problems with code
private List<int> XList = new List<int>();
private List<int> YList = new List<int>();
private Random randoms = new Random();
//private int index = -1;
private void Form1_Load(object sender, EventArgs e)
{
chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.NotSet; // Set the grid type to dashed line
chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash; // Set the grid type to dashed line
chart1.Series[0].IsValueShownAsLabel = true;// Set the display number
for (int i = 0; i < 6; i++)
{
XList.Add(i);
YList.Add(randoms.Next(10, 100));
}
// It is written in the same way as above chart1.ChartAreas[0] similar
chart1.Series["Series1"].Points.DataBindXY(XList, YList);
}effect

At this point, the effect we want is almost the same
3、 ... and 、 Broken line diagram
1. Chart settings
Create a new one .NET Framework Type of Winfrom project , The operation is the same as above , take ChartType This is set to Line, And in Form1 Add a button to the interface


After running , The chart is still blank

2. Data binding
Add code
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace Broken line diagram
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private List<int> XList = new List<int>();
private List<int> YList = new List<int>();
private Random randoms = new Random();
private int index = -1;
private void Form1_Load(object sender, EventArgs e)
{
chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.NotSet; // Set the grid type to dashed line
chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash; // Set the grid type to dashed line
chart1.Series[0].IsValueShownAsLabel = true;// Set the display number
}
private void button1_Click(object sender, EventArgs e)
{
index++;
XList.Add(index);
YList.Add(randoms.Next(10, 100));
//chart1.Series[0].Points.AddXY(index, randoms.Next(10, 100));
chart1.Series[0].Points.DataBindXY(XList, YList);
}
}
}
After operation , Click the add button , The effect is as follows

Here you will find a problem , In the figure to 93 This point , It has reached the top , The words are half blocked , Here you can use code to set , such as , Traverse the whole Y The value of the shaft , Then calculate the maximum and minimum values , And give chart1 Of Maximum,Minimum assignment , You can center the line chart
chart1.ChartAreas[0].AxisY.Maximum = 200;If you want the following effect , You can also refer to my post , although DLL Dissimilarity , The writing method is basically the same , In the following source code, there is also this case to the effect , You can support me if you need me , thank you .

Source download : Click to download
end
If this post is useful to you , welcome Focus on + give the thumbs-up + Leaving a message. , thank you
end
边栏推荐
- 破解湖+仓混合架构顽疾,星环科技推出自主可控云原生湖仓一体平台
- What are the top level Chinese programmers?
- A tour of gRPC:02 - 从proto生成代码
- Key sprite fighting monsters - multi window and multi thread background skills
- What are the financial products suitable for the poor in 2022?
- 全面剖析Seata 分布式事务 AT 与XA
- 自学编程能看得懂代码,但是自己写不出来怎么办
- Tool chain empowers hundreds of companies, horizon opens the "Matthew effect" of mass production of intelligent driving
- apache atlas断点查看
- 分片信息调哪个参数呢?用的是MySQLsource stream api,不是table api
猜你喜欢

The third sprint of Wei long La Tiao: the growth rate of performance declined, and Liu Weiping and Liu Fuping cashed out in advance

都3年测试经验了,用例设计还不知道状态迁移法?

Cerebral Cortex:从任务态和静息态脑功能连接预测儿童数学技能

Selenium 凭什么成为 Web 自动化测试的首选?(内附源码)

我,大厂测试员,降薪50%去国企,后悔了...

MATLAB给数据加噪声/扰动

卫龙辣条第三次冲刺上市:业绩增速下滑,刘卫平、刘福平提前套现

Mysql database Basics: introduction to data types

MySQL基础——事务

暑期数据可视化分析展示效果
随机推荐
美国芯片再遭重击,Intel或将被台积电击败而沦落至全球第三
Tianlong Babu TLBB series - how to make pets learn twelve full skills
redolog和binlog
资讯 | 扎克伯格被评为全球IT业最不谨慎的CEO;中国移动研发系留式无人机应急通信高空基站
Sophon Base 3.1 推出MLOps功能,为企业AI能力运营插上翅膀
「BUAA OO Unit 4 HW16」第四单元总结与课程回顾
进阶 | webgl性能优化初尝
locust性能压测工具
Top the list for 10 consecutive years? What is the "most common" programming language for programmers?
又拍云 Redis 的改进之路
【第28天】给定一个字符串S,请你判断它是否为回文字符串 | 回文的判断
isEmpty 和 isBlank 的用法区别,居然一半的人答不上来?
天龙八部TLBB系列 - 如何让宠物学习十二满技能
How to distinguish between instructions and data in the "group counting" CPU
Cortical traceability analysis of ERP
Key wizard play monster learning - multi window and multi thread background judgment of character, pet blood volume and pet happiness
毕业生迷茫,中年人焦虑,职场路怎么越走越宽?
C11新特性——auto、decltype类型指示符
MATLAB给数据加噪声/扰动
How do I create a contact form in WordPress?