-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathStackedBarTimeSeriesChart.razor
92 lines (82 loc) · 1.74 KB
/
StackedBarTimeSeriesChart.razor
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
81
82
83
84
85
86
87
88
89
90
91
92
@using Vizor.ECharts;
<Vizor.ECharts.EChart Options="@options" DataLoader="LoadChartData" Width="auto" Height="400px" />
@code {
private ChartOptions options = new()
{
Tooltip = new()
{
Trigger = TooltipTrigger.Axis,
AxisPointer = new()
{
Type = AxisPointerType.Shadow
}
},
Legend = new() { },
Grid = new()
{
Left = "3%",
Right = "4%",
Bottom = "3%",
ContainLabel = true
},
YAxis = new()
{
Type = AxisType.Value
},
XAxis = new()
{
Type = AxisType.Time
},
Series = new()
};
// see https://stackoverflow.com/questions/69215766/echarts-separate-series-based-on-dataset-field
private void LoadChartData()
{
// create Bar series for each
var names = new string[] { "A", "B", "C", "D" };
var series = new List<BarSeries>();
for (int seriesIndex = 0; seriesIndex < 4; ++seriesIndex)
{
var s = new BarSeries()
{
Name = names[seriesIndex],
Stack = "StackName",
Label = new()
{
Show = true
},
Emphasis = new()
{
Focus = "series"
},
DatasetIndex = seriesIndex,
Encode = new()
{
X = "time",
Y = "count"
}
};
series.Add(s);
}
options.Series!.Clear();
options.Series!.AddRange(series);
// create a dataset
var start = new DateOnly(2023, 8, 1);
var rnd = new Random();
var datasets = new List<Dataset>();
for (int seriesIndex = 0; seriesIndex < 4; ++seriesIndex)
{
var values = new List<SeriesData<DateOnly, int>>(10 * 4);
for (int i = 0; i < 10; ++i)
{
values.Add(new(start.AddDays(i), rnd.Next(300)));
}
datasets.Add(new Dataset()
{
Dimensions = new string[] { "time", "count" },
Source = values
});
}
options.DatasetList = datasets;
}
}