1.软件版本
2.代码
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 WindowsFormsApp3
{
public partial class Form1 : Form
{
public int MAX = 100;
public int i = 1;
Random r = new Random();
public Form1()
{
InitializeComponent();
Chart_design();
}
private void button1_Click(object sender, EventArgs e)
{
random();
chart1.ChartAreas[0].AxisX.ScaleView.Scroll(ScrollType.Last);
}
public void random()
{
textBox1.Text += r.Next(0,100)+"\r\n";
this.textBox1.Select(this.textBox1.Text.Length, 0);
this.textBox1.ScrollToCaret();
this.chart1.Series[0].Points.AddXY(i, r.Next(0, 100));
i++;
}
public void Chart_design()
{
this.chart1.ChartAreas[0].AxisX.Minimum = 0;
this.chart1.ChartAreas[0].AxisY.Maximum = MAX;
chart1.ChartAreas[0].AxisX.ScaleView.Size = 5;
chart1.Series[0].ToolTip = "#VALX,#VALY";
}
}
}
3.效果
4.参考
B站视频
|