127 lines
5.7 KiB
Plaintext
127 lines
5.7 KiB
Plaintext
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 SetTools.Views
|
||
{
|
||
public partial class Form1chart : Form
|
||
{
|
||
public Form1chart()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
int cnt = 0;
|
||
private Random m_Random = new Random((int)DateTime.Now.Ticks);
|
||
|
||
private void Form1chart_Load(object sender, EventArgs e)
|
||
{
|
||
//timer1.Enabled = true;
|
||
chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Size = 20;//x坐标显示的个数------------控制这个数量的大小进行缩放
|
||
chart1.ChartAreas[0].AxisX.LabelStyle.IntervalType = DateTimeIntervalType.Seconds;//设置x轴间隔值单位:秒
|
||
chart1.ChartAreas[0].AxisX.LabelStyle.Interval = 1;//设置X轴的值的间隔大小
|
||
chart1.ChartAreas[0].AxisX.LabelStyle.IsEndLabelVisible = false;//是否在轴末尾显示标记
|
||
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss";//设置X轴的数据样式
|
||
chart1.ChartAreas[0].AxisX.ScaleView.MinSizeType = DateTimeIntervalType.Seconds;
|
||
chart1.ChartAreas[0].AxisX.ScaleView.SizeType = DateTimeIntervalType.Seconds; //度量单位
|
||
chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSize = 1;
|
||
chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSizeType = DateTimeIntervalType.Seconds;
|
||
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Seconds;
|
||
chart1.ChartAreas[0].AxisX.Enabled = AxisEnabled.True;//将X轴始终展示
|
||
chart1.ChartAreas[0].AxisY.Enabled = AxisEnabled.True;//将Y轴始终展示
|
||
chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Gray;//设置X轴网格线颜色
|
||
chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Gray;//设置Y轴网格线颜色
|
||
chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;//关闭系统的滚动条,也可以不关闭,就可以滑动
|
||
chart1.Series[0].BorderWidth = 2;//线宽
|
||
|
||
|
||
//以3D形式展示
|
||
//chart1.ChartAreas[0].Area3DStyle.Enable3D = true;
|
||
|
||
//设置坐标轴标题
|
||
chart1.ChartAreas[0].AxisY.Title = "电压值";
|
||
chart1.ChartAreas[0].AxisY.TitleForeColor = System.Drawing.Color.Crimson;
|
||
chart1.ChartAreas[0].AxisY.TextOrientation = TextOrientation.Horizontal;
|
||
////设置网格间隔(这里设成0.5,看得更直观一点)
|
||
//chart1.ChartAreas[0].AxisX.MajorGrid.Interval = 0.5;
|
||
|
||
|
||
//this.chart1.Series.Clear();//先将series清除
|
||
// //设置X/Y样式
|
||
//chart1.ChartAreas[0].AxisY.Title = "电压";
|
||
chart1.ChartAreas[0].AxisX.Title = "时间";
|
||
//chart1.ChartAreas[0].AxisX.LabelStyle.Angle = 0;
|
||
//chart1.ChartAreas[0].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;
|
||
//chart1.ChartAreas[0].AxisY.IntervalAutoMode = IntervalAutoMode.VariableCount;
|
||
////chart1.ChartAreas[0].AxisX.Enabled = AxisEnabled.False;
|
||
////chart1.ChartAreas[0].AxisY.Enabled = AxisEnabled.False;
|
||
//chart1.Titles[0].Text = "";
|
||
|
||
|
||
//设置char样式
|
||
//this.chart1.Series.Add("数量");
|
||
//chart1.Series["数量"].MarkerColor = Color.Black;//设置标志
|
||
//chart1.Series["数量"].MarkerSize = 1;
|
||
//chart1.Series["数量"].MarkerStyle = MarkerStyle.Square;
|
||
//chart1.Series["数量"].IsValueShownAsLabel = false;//是否显示值
|
||
//chart1.Series["数量"].ChartType = SeriesChartType.Spline;//设置显示样式
|
||
//chart1.Series["数量"].BorderWidth = 1;
|
||
//chart1.Series["数量"].Color = Color.Blue;
|
||
//chart1.Series["数量"].ToolTip = "原材料数量";
|
||
//chart1.Series["数量"].YValueType = ChartValueType.Double;
|
||
|
||
////McsDataReader reader = (McsDataReader)Mes.Core.Service.DatabaseAccessService.execute(qf.QuerySql01, Mes.Core.Service.ReturnType.RESULTSET);
|
||
////if (reader.rowNumber > 0)
|
||
////{
|
||
//// while (reader.Read())
|
||
//// {
|
||
//// chart1.Series["数量"].Points.AddXY(reader.getString(1), reader.getString(0));
|
||
//// }
|
||
////}
|
||
//chart1.ChartAreas[0].AxisY.Minimum = 0;
|
||
//chart1.ChartAreas[0].Axes[1].LabelStyle.Format = "N0";
|
||
|
||
|
||
|
||
}
|
||
|
||
private void timer1_Tick(object sender, EventArgs e)
|
||
{
|
||
//chart1.Series[0].Points.AddY(cnt * cnt);
|
||
//label1.Text = cnt.ToString();
|
||
//cnt++;
|
||
int i = 0;
|
||
Random random = new Random();
|
||
i = chart1.Series[0].Points.AddXY(DateTime.Now, random.Next(1, 20));
|
||
if (chart1.ChartAreas[0].AxisX.ScaleView.Size > 0)
|
||
{
|
||
chart1.ChartAreas[0].AxisX.ScaleView.Scroll(System.Windows.Forms.DataVisualization.Charting.ScrollType.Last);
|
||
}
|
||
|
||
chart1.Series[0].Points[i].MarkerStyle = MarkerStyle.Diamond;
|
||
chart1.Series[0].Points[i].MarkerColor = Color.Red;
|
||
chart1.Series[0].Points[i].MarkerBorderWidth = 3;
|
||
chart1.Series[0].Points[i].MarkerSize = 10;
|
||
chart1.Series[0].Points[i].Label = "序号:" + Convert.ToString(i) + "\r\n" + "温度:" + "#VAL";
|
||
chart1.Series[0].Points[i].IsValueShownAsLabel = true;
|
||
|
||
|
||
}
|
||
|
||
private void button1_Click(object sender, EventArgs e)
|
||
{
|
||
timer1.Enabled = !timer1.Enabled;
|
||
}
|
||
}
|
||
}
|