当前位置:网站首页>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
边栏推荐
- MATLAB给数据加噪声/扰动
- 按键精灵打怪学习-多窗口多线程后台判断人物、宠物血量和宠物快乐度
- C11新特性——auto、decltype类型指示符
- 新股民如何网上开户?究竟网上开户是否安全么?
- apache atlas断点查看
- 关于开展2022年江苏省重点领域 首版次软件产品征集工作的通知
- 挖财学堂证券开户安全嘛?
- How to distinguish between instructions and data in the "group counting" CPU
- The latest agenda of dtcc2022 China database technology conference was released
- After 3 years of testing experience, do you know the state transition method for use case design?
猜你喜欢
随机推荐
After 3 years of testing experience, do you know the state transition method for use case design?
天龙八部TLBB系列 - 网单用数据库修改为其他门派
To solve the stubborn problem of Lake + warehouse hybrid architecture, Star Ring Technology launched an independent controllable cloud native Lake warehouse integrated platform
UWB precise positioning scheme, centimeter level high-precision technology application, intelligent pairing induction technology
Telnet+ftp to control and upgrade the equipment
全面剖析Seata 分布式事务 AT 与XA
小程序在产业互联网有「大」作为
[try to hack] upload labs (temporarily write to 12)
What is the strength of a software testing engineer who can get a salary increase twice a year?
It's also a test. Why do others get an annual salary of 30w+?
Key sprite fighting monsters - multi window and multi thread background skills
Apache atlas breakpoint view
The difference between Magento and WordPress
Metadata management Apache Atlas Compilation integration deployment and testing
MATLAB给数据加噪声/扰动
Locust performance pressure test tool
稳定币风险状况:USDT 和 USDC 安全吗?
C language -- printf print base prefix
卫龙辣条第三次冲刺上市:业绩增速下滑,刘卫平、刘福平提前套现
把这份关于软件测试一系列笔记研究完,进大厂是个“加分项”...









