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 { 2, 5, 4, 4, 56, 7, 45, 24, 7, 7, 3546, 24, 2345, 236, 3567, 2456 }; var errValues = new ObservableCollection { 3, 1, 6, 4, 56, 7, 45, 24, 7, 7, 3546, 24, 2345, 236, 3567, 2456 }; var barSeries = new ISeries[] { new ColumnSeries { Name = "Con", Values = conValues, XToolTipLabelFormatter = (d)=>$"#{d.Index+1}", }, new ColumnSeries { Name = "Err", Values = errValues, } }; barChart.Series = barSeries; barChart.XAxes = [new Axis { Labeler = (d)=>$"#{d+1}", }]; var lineDataSource = new ObservableCollection() { 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 { 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) { } } }