using CommunityToolkit.Mvvm.ComponentModel; using LiveChartsCore; using LiveChartsCore.Defaults; using LiveChartsCore.SkiaSharpView; using LiveChartsCore.SkiaSharpView.Painting; using LiveChartsCore.SkiaSharpView.VisualElements; using SkiaSharp; using System.Collections.ObjectModel; using System.Drawing; namespace B20UVLog.ViewModels { internal class AxisDataViewModel : ObservableObject { private static SKColor _SKColor1 = new(0, 140, 214); private static SKColor _SKColor2 = new(103, 194, 58); private static SKColor _SKColor3 = new(230, 162, 60); private static SKColor _SKColor4 = new(245, 108, 108); private static SKColor _SKColor5 = new(144, 147, 153); private readonly ObservableCollection _observableValues; public AxisDataViewModel() { _observableValues = [new(3), new(1), new(4), new(1), new(5), new(9), new(2), new(6)]; Series = [ //new ColumnSeries //{ // Name = "Bar", // Values = _observableValues, // Fill = GenSolidColorPaint(_SKColor2) //}, new LineSeries { Name = "Line1", Values = _observableValues, Stroke = GenSolidColorPaint(_SKColor1), GeometryStroke = GenSolidColorPaint(_SKColor1), Fill = null, }, new LineSeries { Name = "Line2", Values = [new(6), new(2), new(9), new(5), new(1), new(4), new(1), new(3)], Stroke = GenSolidColorPaint(_SKColor2), GeometryStroke = GenSolidColorPaint(_SKColor2), Fill = null, }, ]; } private static SolidColorPaint GenSolidColorPaint(SKColor color, float strokeThickness = 4) { return new SolidColorPaint(color) { StrokeThickness = strokeThickness, }; } public ObservableCollection Series { get; set; } public LabelVisual Title { get; set; } = new LabelVisual { Text = "标题", TextSize = 25, Padding = new LiveChartsCore.Drawing.Padding(15), Paint = new SolidColorPaint { Color = SKColors.Black, SKTypeface = SKFontManager.Default.MatchCharacter('汉'), }, }; } }