Skip to content

Commit 6e75eed

Browse files
Merge pull request #7257 from syncfusion-content/998039-acc-legend
998039: Added UG documentation for legend template.
2 parents fe5111b + 5f6d974 commit 6e75eed

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
46.8 KB
Loading

blazor/accumulation-chart/legend.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,70 @@ When the legend text exceeds the container, the text can be wrapped by using [Te
389389

390390
{% previewsample "https://blazorplayground.syncfusion.com/embed/htLqsrMJWRuPUEHB?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" backgroundimage "[Blazor Accumulation Chart Legend with Wrap](images/legend/blazor-accumulation-chart-legend-wrap.png)" %}
391391

392+
## Legend Template
393+
394+
Legend templates allow you to replace default legend icons and text with custom HTML or Blazor markup for each series. This enables branded styles, richer content (icons, multi-line text, badges), improved readability, and localization.
395+
396+
To use, add a `LegendItemTemplate` inside any [AccumulationChartSeries](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.AccumulationChartSeries.html) you want to customize. The rendered content becomes the legend item and can be styled with CSS. Legend interactions (click to toggle series) remain unless [ToggleVisibility](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.AccumulationChartLegendSettings.html#Syncfusion_Blazor_Charts_AccumulationChartLegendSettings_ToggleVisibility) is set to false. Templates work with all legend positions, alignments, and paging.
397+
398+
**Text** : Gets or sets the text to render for the current legend item in the template. Defaults to the value from the field mapped by AccumulationChartSeries.XName.
399+
400+
**Data** : Gets the data item from AccumulationChartSeries.DataSource bound to the current legend item. Use this to access additional fields (for example, images, badges, or localized text) inside the template.
401+
402+
```
403+
@using Syncfusion.Blazor.Charts
404+
405+
@* Initialize the accumulation chart component and configure its essential features *@
406+
<SfAccumulationChart Title="Mobile Browser Statistics">
407+
408+
@* Display the legend and allow toggling visibility on interaction *@
409+
<AccumulationChartLegendSettings Visible="true" >
410+
</AccumulationChartLegendSettings>
411+
412+
<AccumulationChartSeriesCollection>
413+
@* Define a pie series with X and Y mappings and color mapping *@
414+
<AccumulationChartSeries DataSource="@StatisticsDetails" XName="Browser" YName="Users" Name="Browser" PointColorMapping="Color">
415+
@* Render a custom legend item using the template context *@
416+
<LegendItemTemplate>
417+
@{
418+
var info = context as AccumulationChartLegendInfo;
419+
var browser = info?.Data?["Browser"]?.ToString() ?? "";
420+
var users = info?.Data?["Users"] is null ? 0 : Convert.ToDouble(info.Data["Users"]);
421+
}
422+
<div style="display:flex; align-items:center; gap:8px; padding:4px 0;">
423+
<div style="display:flex; flex-direction:column; line-height:1.1;">
424+
<span style="font-weight:800; font-size:14px; color: @info.Data["Color"]">@browser</span>
425+
<span style="font-size:12px; opacity:0.8;"><b>@users million</b> people use @browser</span>
426+
</div>
427+
</div>
428+
</LegendItemTemplate>
429+
</AccumulationChartSeries>
430+
</AccumulationChartSeriesCollection>
431+
432+
</SfAccumulationChart>
433+
434+
@code {
435+
public class Statistics
436+
{
437+
public string Browser { get; set; }
438+
public double Users { get; set; }
439+
public string Color { get; set; }
440+
}
441+
442+
public List<Statistics> StatisticsDetails = new()
443+
{
444+
new Statistics { Browser = "Chrome", Users = 37, Color = "#a16ee5" },
445+
new Statistics { Browser = "UC Browser", Users = 17, Color = "#f7ce69" },
446+
new Statistics { Browser = "iPhone", Users = 19, Color = "#55a5c2" },
447+
new Statistics { Browser = "Others", Users = 4, Color = "#7ddf1e" },
448+
new Statistics { Browser = "Opera", Users = 11, Color = "#ff6ea6" },
449+
new Statistics { Browser = "Android", Users = 12, Color = "#7953ac" },
450+
};
451+
452+
}
453+
```
454+
![Legend Template in Blazor Accumulation Chart](images/legend/blazor-accumulation-chart-legend-template.png)
455+
392456
N> Refer to the [Blazor Charts](https://www.syncfusion.com/blazor-components/blazor-charts) feature tour page for its groundbreaking feature representations and also explore the [Blazor Accumulation Chart Example](https://blazor.syncfusion.com/demos/chart/pie?theme=bootstrap5) to know about the various features of accumulation charts and how it is used to represent numeric proportional data.
393457

394458
* [Grouping](./grouping)

0 commit comments

Comments
 (0)