chart柱状图效果展示
文章来源:https://www.toymoban.com/news/detail-531186.html
实现
1)拖入Chart控件设置初始化属性;
2)拖入timer控件设置时间和启动;
3)代码实现文章来源地址https://www.toymoban.com/news/detail-531186.html
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 Chartfresh
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer_Tick(object sender, EventArgs e)
{
chart1.Series[0].Points.Clear();
chart1.Series.Clear();
chart1.ChartAreas.Clear();
Series series = new Series("series");
ChartArea chartArea1 = new ChartArea();
//随机数方便做测试
Random ra = new Random();
series.ChartType = SeriesChartType.Column;
series.BorderColor = System.Drawing.Color.Red;
series.BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
series.BorderWidth = 1;
series.Color = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));
series.IsValueShownAsLabel = true;
series.LabelForeColor = System.Drawing.Color.Red;
chartArea1.AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
chartArea1.AxisX.IsLabelAutoFit = false;
// chartArea1.AxisX.LabelStyle.IsStaggered = true;
//X轴标签旋转90度
chartArea1.AxisX.LabelStyle.Angle = 90;
//隐藏网格线
chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.Transparent;
chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.Transparent;
series.Points.AddXY("num_1", ra.Next(1, 50).ToString());
series.Points.AddXY("num_2", ra.Next(1, 50).ToString());
series.Points.AddXY("num_3", ra.Next(1, 50).ToString());
series.Points.AddXY("num_4", ra.Next(1, 50).ToString());
series.Points.AddXY("num_5", ra.Next(1, 50).ToString());
series.Points.AddXY("num_6", ra.Next(1, 50).ToString());
series.Points.AddXY("num_7", ra.Next(1, 50).ToString());
series.Points.AddXY("num_8", ra.Next(1, 50).ToString());
series.Points.AddXY("num_9", ra.Next(1, 50).ToString());
series.Points.AddXY("num_10", ra.Next(1, 50).ToString());
series.Points.AddXY("num_11", ra.Next(1, 50).ToString());
series.Points.AddXY("num_12", ra.Next(1, 50).ToString());
series.Points.AddXY("num_13", ra.Next(1, 50).ToString());
series.Points.AddXY("num_14", ra.Next(1, 50).ToString());
series.Points.AddXY("num_15", ra.Next(1, 50).ToString());
series.Points.AddXY("num_16", ra.Next(1, 50).ToString());
series.Points.AddXY("num_17", ra.Next(1, 50).ToString());
series.Points.AddXY("num_18", ra.Next(1, 50).ToString());
series.Points.AddXY("num_19", ra.Next(1, 50).ToString());
series.Points.AddXY("num_20", ra.Next(1, 50).ToString());
series.Points.AddXY("num_21", ra.Next(1, 50).ToString());
series.Points.AddXY("num_22", ra.Next(1, 50).ToString());
series.Points.AddXY("num_23", ra.Next(1, 50).ToString());
series.Points.AddXY("num_24", ra.Next(1, 50).ToString());
series.Points.AddXY("num_25", ra.Next(1, 50).ToString());
series.Points.AddXY("num_26", ra.Next(1, 50).ToString());
series.Points.AddXY("num_27", ra.Next(1, 50).ToString());
series.Points.AddXY("num_28", ra.Next(1, 50).ToString());
series.Points.AddXY("num_29", ra.Next(1, 50).ToString());
series.Points.AddXY("num_30", ra.Next(1, 50).ToString());
series.Points.AddXY("num_31", ra.Next(1, 50).ToString());
series.Points.AddXY("num_32", ra.Next(1, 50).ToString());
chart1.Series.Add(series);
chart1.ChartAreas.Add(chartArea1);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Author:freesheep720
到了这里,关于C# 中Chart动态柱状图实现的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!