-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathGradient.razor
More file actions
66 lines (60 loc) · 2.09 KB
/
Gradient.razor
File metadata and controls
66 lines (60 loc) · 2.09 KB
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
@page "/workarounds/gradient"
@using ChartJs.Blazor.LineChart
@layout SampleLayout
@inject IJSRuntime jsRuntime
<Chart @ref="_chart" Config="_config" SetupCompletedCallback="@SetupCompletedCallback"></Chart>
@code {
private const int InitalCount = 7;
private LineConfig _config;
private Random _rng = new Random();
private Chart _chart;
protected override void OnInitialized()
{
_config = new LineConfig
{
Options = new LineOptions
{
Responsive = true,
Title = new OptionsTitle
{
Display = true,
Text = "ChartJs.Blazor Line Chart with Gradient"
},
Scales = new Scales
{
XAxes = new List<CartesianAxis>
{
new CategoryAxis
{
ScaleLabel = new ScaleLabel
{
LabelString = "Month"
}
}
},
YAxes = new List<CartesianAxis>
{
new LinearCartesianAxis
{
ScaleLabel = new ScaleLabel
{
LabelString = "Value"
}
}
}
}
}
};
IDataset<int> dataset1 = new LineDataset<int>(RandomScalingFactor(InitalCount).Select(i => i + 100))
{
Label = "My first dataset",
// Do not set BackgroundColor in C#, otherwise it will override the js value on Setup/Update
BorderColor = "#ff6c23",
Fill = FillingMode.Origin
};
_config.Data.Labels.AddRange(Months.Take(InitalCount));
_config.Data.Datasets.Add(dataset1);
}
private async Task SetupCompletedCallback() =>
await jsRuntime.InvokeVoidAsync("workaroundGradient", _chart.ChartId);
}