-
-
Notifications
You must be signed in to change notification settings - Fork 389
feat(Chart): add Total/Tooltip/CategoryLabel format parameter #8256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,18 +8,11 @@ namespace BootstrapBlazor.Server.Components.Samples.Charts; | |
| /// <summary> | ||
| /// Bar 图表示例 | ||
| /// </summary> | ||
| [JSModuleAutoLoader("Samples/Charts/Bar.razor.js", JSObjectReference = true)] | ||
| public partial class Bar | ||
| { | ||
| private int _barDatasetCount = 2; | ||
| private int _barDataCount = 7; | ||
|
|
||
| private string CustomTooltipId => $"custom_tooltip_{Id}"; | ||
|
|
||
| private string CustomCategoryLabelId => $"custom_category_label_{Id}"; | ||
|
|
||
| private string TotalDataLabelId => $"total_data_label_{Id}"; | ||
|
|
||
| private int BarDatasetCount { get; set; } = 2; | ||
|
|
||
| private int BarDataCount { get; set; } = 7; | ||
|
|
@@ -44,16 +37,6 @@ protected override void OnAfterRender(bool firstRender) | |
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc/> | ||
| /// </summary> | ||
| protected override async Task InvokeInitAsync() | ||
| { | ||
| await InvokeVoidAsync("customTooltip", CustomTooltipId); | ||
| await InvokeVoidAsync("customCategoryLabel", CustomCategoryLabelId); | ||
| await InvokeVoidAsync("customTotalDataLabel", TotalDataLabelId); | ||
| } | ||
|
|
||
| private Task OnAfterInit() | ||
| { | ||
| Logger.Log("Bar initialization is complete"); | ||
|
|
@@ -256,6 +239,12 @@ private Task<ChartDataSource> OnInitTotalDataLabel() | |
| ds.Options.Title = "Stacked total"; | ||
| ds.Options.ShowDataLabel = true; | ||
| ds.Options.ShowTotalDataLabel = true; | ||
| ds.Options.TotalDataLabelFormatter = "Total: {total}"; | ||
| ds.Options.TotalDataLabelColor = "#fff"; | ||
| ds.Options.TotalDataLabelBackgroundColor = "rgb(75, 192, 192)"; | ||
| ds.Options.TotalDataLabelBorderRadius = 4; | ||
| ds.Options.TotalDataLabelPadding = 6; | ||
| ds.Options.TotalDataLabelFontWeight = "bold"; | ||
| ds.Options.Anchor = ChartDataLabelPosition.Center; | ||
| ds.Options.X.Title = "name"; | ||
| ds.Options.Y.Title = "Numerical value"; | ||
|
|
@@ -275,6 +264,21 @@ private Task<ChartDataSource> OnInitTotalDataLabel() | |
| return Task.FromResult(ds); | ||
| } | ||
|
|
||
| private Task<ChartDataSource> OnInitCustomTooltip() | ||
| { | ||
| var ds = OnInit(false).Result; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): OnInitCustomCategoryLabel should also avoid using .Result on the async OnInit(false) method. This method also blocks synchronously on |
||
| ds.Options.TooltipTitleFormatter = "Day {label}"; | ||
| ds.Options.TooltipLabelFormatter = " {datasetLabel}: {value} units"; | ||
| return Task.FromResult(ds); | ||
| } | ||
|
|
||
| private Task<ChartDataSource> OnInitCustomCategoryLabel() | ||
| { | ||
| var ds = OnInit(false).Result; | ||
| ds.Options.CategoryLabelFormatter = "Day {label}"; | ||
| return Task.FromResult(ds); | ||
| } | ||
|
|
||
| private Task<ChartDataSource> OnInitAutoSkip(bool autoSkip) | ||
| { | ||
| var ds = new ChartDataSource(); | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Avoid blocking on the async OnInit(false) call with .Result inside OnInitCustomTooltip.
Blocking on
OnInit(false).Resultin a Blazor component can cause deadlocks and thread-pool exhaustion, and complicates async control flow. MakeOnInitCustomTooltipasync, useawait OnInit(false), and returnTask<ChartDataSource>via async/await instead ofTask.FromResultto keep the method fully asynchronous.