* UILineChart:增加实时数据的Demo

This commit is contained in:
Sunny 2021-07-21 17:51:14 +08:00
parent 2456e75e06
commit 2ef88246cd
13 changed files with 90 additions and 8 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -28,12 +28,15 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.uiSymbolButton1 = new Sunny.UI.UISymbolButton();
this.uiImageButton3 = new Sunny.UI.UIImageButton();
this.uiImageButton2 = new Sunny.UI.UIImageButton();
this.uiImageButton1 = new Sunny.UI.UIImageButton();
this.uiLine1 = new Sunny.UI.UILine();
this.LineChart = new Sunny.UI.UILineChart();
this.uiSymbolButton2 = new Sunny.UI.UISymbolButton();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.PagePanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.uiImageButton3)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.uiImageButton2)).BeginInit();
@ -42,6 +45,7 @@
//
// PagePanel
//
this.PagePanel.Controls.Add(this.uiSymbolButton2);
this.PagePanel.Controls.Add(this.uiSymbolButton1);
this.PagePanel.Controls.Add(this.uiImageButton3);
this.PagePanel.Controls.Add(this.uiImageButton2);
@ -130,9 +134,26 @@
this.LineChart.Text = "uiLineChart1";
this.LineChart.PointValue += new Sunny.UI.UILineChart.OnPointValue(this.LineChart_PointValue);
//
// uiSymbolButton2
//
this.uiSymbolButton2.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiSymbolButton2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiSymbolButton2.Location = new System.Drawing.Point(454, 466);
this.uiSymbolButton2.MinimumSize = new System.Drawing.Size(1, 1);
this.uiSymbolButton2.Name = "uiSymbolButton2";
this.uiSymbolButton2.Padding = new System.Windows.Forms.Padding(28, 0, 0, 0);
this.uiSymbolButton2.Size = new System.Drawing.Size(100, 27);
this.uiSymbolButton2.Symbol = 61463;
this.uiSymbolButton2.TabIndex = 36;
this.uiSymbolButton2.Text = "实时";
this.uiSymbolButton2.Click += new System.EventHandler(this.uiSymbolButton2_Click);
//
// timer1
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// FLineChart
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(800, 574);
this.Name = "FLineChart";
@ -154,5 +175,7 @@
private UIImageButton uiImageButton1;
private UILine uiLine1;
private UILineChart LineChart;
private UISymbolButton uiSymbolButton2;
private System.Windows.Forms.Timer timer1;
}
}

View File

@ -13,6 +13,10 @@ namespace Sunny.UI.Demo.Charts
private void uiSymbolButton1_Click(object sender, EventArgs e)
{
timer1.Stop();
DateTime dt = new DateTime(2020, 10, 4);
UILineOption option = new UILineOption();
option.ToolTip.Visible = true;
option.Title = new UITitle();
@ -22,7 +26,6 @@ namespace Sunny.UI.Demo.Charts
option.XAxisType = UIAxisType.DateTime;
var series = option.AddSeries(new UILineSeries("Line1"));
DateTime dt = new DateTime(2020, 10, 4);
series.Add(dt.AddHours(0), 1.2);
series.Add(dt.AddHours(1), 2.2);
series.Add(dt.AddHours(2), 3.2);
@ -55,8 +58,10 @@ namespace Sunny.UI.Demo.Charts
option.XAxis.Name = "日期";
option.YAxis.Name = "数值";
option.XAxis.AxisLabel.DateTimeFormat = DateTimeEx.DateTimeFormat;
option.XAxis.AxisLabel.DateTimeFormat = "yyyy-MM-dd HH:mm";
option.XAxis.AxisLabel.AutoFormat = false;
option.YAxis.AxisLabel.DecimalCount = 1;
option.YAxis.AxisLabel.AutoFormat = false;
option.XAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = dt.AddHours(3).DateTimeString(), Value = new DateTimeInt64(dt.AddHours(3)) });
option.XAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = dt.AddHours(6).DateTimeString(), Value = new DateTimeInt64(dt.AddHours(6)) });
@ -89,5 +94,43 @@ namespace Sunny.UI.Demo.Charts
Console.WriteLine(sb.ToString());
}
private void uiSymbolButton2_Click(object sender, EventArgs e)
{
index = 0;
UILineOption option = new UILineOption();
option.ToolTip.Visible = true;
option.Title = new UITitle();
option.Title.Text = "SunnyUI";
option.Title.SubText = "LineChart";
var series = option.AddSeries(new UILineSeries("Line1"));
series.Smooth = true;
option.XAxis.AxisLabel.DecimalCount = 1;
option.XAxis.AxisLabel.AutoFormat = false;
option.YAxis.AxisLabel.DecimalCount = 1;
option.YAxis.AxisLabel.AutoFormat = false;
LineChart.SetOption(option);
timer1.Start();
}
int index = 0;
Random random = new Random();
private void timer1_Tick(object sender, EventArgs e)
{
LineChart.Option.AddData("Line1", index, random.NextDouble() * 10);
index++;
if (index > 50)
{
LineChart.Option.XAxis.Max = index + 20;
LineChart.Option.XAxis.MaxAuto = false;
LineChart.Option.XAxis.Min = index - 50;
LineChart.Option.XAxis.MinAuto = false;
}
LineChart.Refresh();
}
}
}

View File

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -10,10 +10,10 @@ namespace Sunny.UI.Demo
{
InitializeComponent();
uiDataGridView1.AddColumn("Column1", "Column1").SetFixedMode(150);
uiDataGridView1.AddColumn("Column2", "Column2").SetFixedMode(150);
uiDataGridView1.AddColumn("Column3", "Column3").SetFixedMode(150);
uiDataGridView1.AddColumn("Column4", "Column4").SetFixedMode(150);
uiDataGridView1.AddColumn("Column1", "Column1");
uiDataGridView1.AddColumn("Column2", "Column2");
uiDataGridView1.AddColumn("Column3", "Column3");
uiDataGridView1.AddColumn("Column4", "Column4");
uiDataGridView1.ReadOnly = true;
for (int i = 0; i < 3610; i++)

View File

@ -57,7 +57,7 @@ namespace Sunny.UI.Demo
Aside.CreateChildNode(parent, AddPage(new FPieChart()));
Aside.CreateChildNode(parent, AddPage(new FDoughnutChart()));
Aside.CreateChildNode(parent, AddPage(new FBarChart()));
Aside.CreateChildNode(parent, AddPage(new FBarChartEx()));
//Aside.CreateChildNode(parent, AddPage(new FBarChartEx()));
Aside.CreateChildNode(parent, AddPage(new FLineChart()));
AddPage(new FColorful());

View File

@ -21,6 +21,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
@ -28,6 +29,7 @@ using System.Windows.Forms;
namespace Sunny.UI
{
[ToolboxItem(false)]
public sealed class UIBarChartEx : UIBarChart
{
protected override void CalcData()

View File

@ -68,6 +68,17 @@ namespace Sunny.UI
NeedDraw = true;
}
public override void Refresh()
{
base.Refresh();
if (Option != null)
{
SetOption(Option);
}
CalcData();
}
protected UIScale XScale;
protected UIScale YScale;
private double[] YLabels;