Skip to content

Commit d06670c

Browse files
authored
feat(Chart): add AddDataset method (#7354)
* doc: 更新示例 * feat(Chart): add AddDataset method
1 parent 3aba824 commit d06670c

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<PackageReference Include="BootstrapBlazor.BarCode" Version="10.0.0" />
3030
<PackageReference Include="BootstrapBlazor.BarcodeGenerator" Version="10.0.0" />
3131
<PackageReference Include="BootstrapBlazor.BootstrapIcon" Version="10.0.0" />
32-
<PackageReference Include="BootstrapBlazor.Chart" Version="10.0.1-beta03" />
32+
<PackageReference Include="BootstrapBlazor.Chart" Version="10.0.1" />
3333
<PackageReference Include="BootstrapBlazor.ChatBot" Version="10.0.0" />
3434
<PackageReference Include="BootstrapBlazor.CherryMarkdown" Version="10.0.1" />
3535
<PackageReference Include="BootstrapBlazor.CodeEditor" Version="10.0.0" />

src/BootstrapBlazor.Server/Components/Samples/Charts/Line.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@page "/chart/line"
1+
@page "/chart/line"
22
@inject IStringLocalizer<Line> Localizer
33
@inject CodeSnippetService CodeSnippetService
44
@inherits WebSiteModuleComponentBase
@@ -11,8 +11,8 @@
1111
<div class="btn-group">
1212
<button class="btn btn-primary" @onclick="e => Utility.RandomData(_lineChart)"><i class="fa-solid fa-chart-line"></i><span>@Localizer["LineOnInitRandomData"]</span></button>
1313
<button class="btn btn-primary" @onclick="OnReloadChart"><i class="fa-solid fa-chart-column"></i><span>@Localizer["LineOnInitReload"]</span></button>
14-
<button class="btn btn-primary" @onclick="e => Utility.AddDataSet(_lineChart, ref _lineDatasetCount)"><i class="fa-solid fa-circle-plus"></i><span>@Localizer["LineOnInitAddDataset"]</span></button>
15-
<button class="btn btn-primary" @onclick="e => Utility.RemoveDataSet(_lineChart, ref _lineDatasetCount)"><i class="fa-solid fa-circle-minus"></i><span>@Localizer["LineOnInitRemoveDataset"]</span></button>
14+
<button class="btn btn-primary" @onclick="AddDataset"><i class="fa-solid fa-circle-plus"></i><span>@Localizer["LineOnInitAddDataset"]</span></button>
15+
<button class="btn btn-primary" @onclick="RemoveDataset"><i class="fa-solid fa-circle-minus"></i><span>@Localizer["LineOnInitRemoveDataset"]</span></button>
1616
<button class="btn btn-primary" @onclick="e => Utility.AddData(_lineChart, ref _lineDataCount)"><i class="fa-solid fa-plus"></i><span>@Localizer["LineOnInitAddingData"]</span></button>
1717
<button class="btn btn-primary" @onclick="e => Utility.RemoveData(_lineChart, ref _lineDataCount)"><i class="fa-solid fa-minus"></i><span>@Localizer["LineOnInitRemoveData"]</span></button>
1818
</div>

src/BootstrapBlazor.Server/Components/Samples/Charts/Line.razor.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
@@ -85,6 +85,26 @@ protected override void OnAfterRender(bool firstRender)
8585
}
8686
}
8787

88+
private async Task AddDataset()
89+
{
90+
var dataset = new ChartDataset()
91+
{
92+
BorderWidth = _randomer.Next(1, 5),
93+
Label = $"Set {DateTime.Now:mmss}",
94+
Data = Enumerable.Range(1, _lineDataCount).Select((i, index) => (object)_randomer.Next(20, 37)),
95+
ShowPointStyle = true,
96+
PointStyle = chartPointStyles[_randomer.Next(0, 9)],
97+
PointRadius = 5,
98+
PointHoverRadius = 10
99+
};
100+
await _lineChart.AddDataset(dataset, 0);
101+
}
102+
103+
private async Task RemoveDataset()
104+
{
105+
await _lineChart.RemoveDatasetAt(0);
106+
}
107+
88108
/// <summary>
89109
/// <inheritdoc/>
90110
/// </summary>

0 commit comments

Comments
 (0)