-
Notifications
You must be signed in to change notification settings - Fork 601
/
Copy pathViewModel.cs
80 lines (67 loc) · 2.59 KB
/
ViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using CommunityToolkit.Mvvm.ComponentModel;
using LiveChartsCore;
using LiveChartsCore.Kernel.Sketches;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;
using SkiaSharp;
namespace ViewModelsSamples.Axes.LabelsRotation;
public class ViewModel : ObservableObject
{
private double _sliderValue = 15;
public ISeries[] Series { get; set; } = [
new LineSeries<double>
{
Values = [200, 558, 458, 249, 457, 339, 587 ],
XToolTipLabelFormatter = (point) =>
$"This is {Environment.NewLine}" +
$"A multi-line label {Environment.NewLine}" +
$"With a value of {Environment.NewLine}" + point.Coordinate.PrimaryValue,
}
];
public ICartesianAxis[] XAxes { get; set; } = [
new Axis
{
// Use the Label property to indicate the format of the labels in the axis
// The Labeler takes the value of the label as parameter and must return it as string
Labeler = (value) =>
$"This is {Environment.NewLine}" +
$"A multi-line label {Environment.NewLine}" +
$"With a value of {Environment.NewLine}" +value * 100,
// The MinStep property lets you define the minimum separation (in chart values scale)
// between every axis separator, in this case we don't want decimals,
// so lets force it to be greater or equals than 1
MinStep = 1,
// labels rotations is in degrees (0 - 360)
LabelsRotation = 45,
SeparatorsPaint = new SolidColorPaint(SKColors.LightGray, 2)
}
];
public ICartesianAxis[] YAxes { get; set; } = [
new Axis
{
LabelsRotation = 15,
// Now the Y axis we will display it as currency
// LiveCharts provides some common formatters
// in this case we are using the currency formatter.
Labeler = Labelers.Currency,
// you could also build your own currency formatter
// for example:
// Labeler = (value) => value.ToString("C")
// But the one that LiveCharts provides creates shorter labels when
// the amount is in millions or trillions
SeparatorsPaint = new SolidColorPaint(SKColors.LightGray, 2)
}
];
public double SliderValue
{
get => _sliderValue;
set
{
if (SetProperty(ref _sliderValue, value))
{
YAxes[0].LabelsRotation = value;
}
}
}
}