123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using LiveChartsCore;
- using LiveChartsCore.Kernel.Sketches;
- using LiveChartsCore.SkiaSharpView;
- using LiveChartsCore.SkiaSharpView.Painting;
- using LiveChartsCore.SkiaSharpView.VisualElements;
- using LiveChartsCore.SkiaSharpView.WinForms;
- using SkiaSharp;
- using System.Collections.ObjectModel;
- using System.Windows.Forms.VisualStyles;
- namespace ReatimeSpeedTest.Gui
- {
- public partial class MainForm : Form
- {
- public MainForm()
- {
- InitializeComponent();
- LiveCharts.Configure(config =>
- config
- .AddDarkTheme()
- .HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('ºº'))// <- Chinese
- );
- }
- private CartesianChart lineChart;
- private CartesianChart barChart;
- private PieChart pieChart;
- private NeedleVisual Needle;
- public class DateModel
- {
- public DateTime DateTime { get; set; }
- public double Value { get; set; }
- }
- private void MainForm_Shown(object sender, EventArgs e)
- {
- var btn = new ToolStripButton("Dbg");
- var toolBarBar = new ToolStrip { RenderMode = ToolStripRenderMode.System, BackColor = BackColor, ForeColor = ForeColor };
- toolBarBar.Items.Add(btn);
- toolBarBar.Items.Add(new ToolStripButton("C") { Alignment = ToolStripItemAlignment.Right, CheckOnClick = true, Checked = true });
- toolBarBar.Items.Add(new ToolStripButton("B") { Alignment = ToolStripItemAlignment.Right, CheckOnClick = true, Checked = true });
- toolBarBar.Items.Add(new ToolStripButton("A") { Alignment = ToolStripItemAlignment.Right, CheckOnClick = true, Checked = true });
- var toolBarLine = new ToolStrip { RenderMode = ToolStripRenderMode.System, BackColor = BackColor, ForeColor = ForeColor };
- toolBarLine.Items.Add(new ToolStripButton("C") { Alignment = ToolStripItemAlignment.Right, CheckOnClick = true, Checked = true });
- toolBarLine.Items.Add(new ToolStripButton("B") { Alignment = ToolStripItemAlignment.Right, CheckOnClick = true, Checked = true });
- toolBarLine.Items.Add(new ToolStripButton("A") { Alignment = ToolStripItemAlignment.Right, CheckOnClick = true, Checked = true });
- lineChart = new() { Dock = DockStyle.Fill };
- barChart = new() { Dock = DockStyle.Fill };
- Needle = new()
- {
- Value = 23.3,
- Fill = new SolidColorPaint(SKColors.Red),
- };
- pieChart = new()
- {
- Dock = DockStyle.Fill,
- InitialRotation = -225,
- MaxAngle = 270,
- MinValue = 0,
- MaxValue = 100,
- // out of livecharts properties...
- Location = new Point(0, 0),
- Size = new Size(50, 50),
- Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom,
- VisualElements = [
- new AngularTicksVisual
- {
- Labeler = value => value.ToString("N1"),
- LabelsSize = 16,
- LabelsOuterOffset = 15,
- OuterOffset = 65,
- TicksLength = 20
- },
- Needle
- ]
- };
- var sph = new SplitContainer { Dock = DockStyle.Fill, Orientation = Orientation.Horizontal, BorderStyle = BorderStyle.FixedSingle };
- var spv = new SplitContainer { Dock = DockStyle.Fill, Orientation = Orientation.Vertical, BorderStyle = BorderStyle.FixedSingle };
- sph.Panel1.Controls.Add(spv);
- sph.Panel2.Controls.Add(lineChart);
- sph.Panel2.Controls.Add(toolBarLine);
- spv.Panel1.Controls.Add(pieChart);
- spv.Panel2.Controls.Add(barChart);
- spv.Panel2.Controls.Add(toolBarBar);
- Controls.Add(sph);
- var conValues = new ObservableCollection<double> { 2, 5, 4, 4, 56, 7, 45, 24, 7, 7, 3546, 24, 2345, 236, 3567, 2456 };
- var errValues = new ObservableCollection<double> { 3, 1, 6, 4, 56, 7, 45, 24, 7, 7, 3546, 24, 2345, 236, 3567, 2456 };
- var barSeries = new ISeries[]
- {
- new ColumnSeries<double>
- {
- Name = "Con",
- Values = conValues,
- XToolTipLabelFormatter = (d)=>$"#{d.Index+1}",
- },
- new ColumnSeries<double>
- {
- Name = "Err",
- Values = errValues,
- }
- };
- barChart.Series = barSeries;
- barChart.XAxes = [new Axis
- {
- Labeler = (d)=>$"#{d+1}",
- }];
- var lineDataSource = new ObservableCollection<DateModel>()
- {
- new() { DateTime = DateTime.Now.AddSeconds(-4), Value = 5 },
- new() { DateTime = DateTime.Now.AddSeconds(-3), Value = 9 },
- new() { DateTime = DateTime.Now.AddSeconds(-2), Value = 2 },
- new() { DateTime = DateTime.Now.AddSeconds(-1), Value = 8 },
- new() { DateTime = DateTime.Now, Value = 6 }
- };
- var lineSeries = new LineSeries<DateModel>
- {
- Name = "Total",
- Values = lineDataSource,
- Mapping = (model, i) => new(model.DateTime.Ticks, model.Value),
- GeometrySize = 5,
- //Fill = new SolidColorPaint(SKColors.Transparent),
- //Stroke = new SolidColorPaint(SKColors.LightSkyBlue),
- //GeometryFill = new SolidColorPaint(SKColors.LightSkyBlue),
- //GeometryStroke = new SolidColorPaint(SKColors.LightSkyBlue),
- XToolTipLabelFormatter = point => point.Model.DateTime.ToString("dd HH:mm:ss.fff"),
- };
- lineChart.Series = [lineSeries];
- lineChart.XAxes = [new Axis
- {
- Name = "Time",
- Labeler = value => new DateTime((long)value).ToString("dd HH:mm")
- }];
- lineChart.YAxes = [new Axis
- {
- Name = "Speed",
- Labeler = value => value.ToString("N2")
- }];
- btn.Click += delegate
- {
- Needle.Value = DateTime.Now.Millisecond;
- lineSeries.Values.Add(new()
- {
- DateTime = DateTime.Now,
- Value = DateTime.Now.Second
- });
- conValues[0] = DateTime.Now.Millisecond;
- errValues[0] = DateTime.Now.Millisecond;
- lineSeries.IsVisible = !lineSeries.IsVisible;
- };
- }
- private void MainForm_Load(object sender, EventArgs e)
- {
- }
- }
- }
|