Skip to content

Commit d7cc92e

Browse files
committed
998039: Added UG documentation for legend template.
1 parent 7fea9f0 commit d7cc92e

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
36.2 KB
Loading

blazor/accumulation-chart/legend.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,61 @@ 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+
```
399+
@using Syncfusion.Blazor.Charts
400+
401+
<SfAccumulationChart Title="Mobile Browser Statistics">
402+
<AccumulationChartSeriesCollection>
403+
<AccumulationChartSeries DataSource="@StatisticsDetails" XName="Browser" YName="Users" Name="Browser" PointColorMapping="Color">
404+
<LegendItemTemplate>
405+
@{
406+
var info = context as AccumulationChartLegendInfo;
407+
var browser = info?.Data?["Browser"]?.ToString() ?? "";
408+
}
409+
<div style="display:flex; align-items:center; gap:8px; padding:4px 0;">
410+
<span style="font-weight:600; color:@info.Data["Color"];">@browser</span>
411+
</div>
412+
</LegendItemTemplate>
413+
<ChildContent>
414+
<AccumulationDataLabelSettings Visible="true" Position="AccumulationLabelPosition.Inside">
415+
<AccumulationChartDataLabelFont Size="12px" Color="white"></AccumulationChartDataLabelFont>
416+
</AccumulationDataLabelSettings>
417+
</ChildContent>
418+
</AccumulationChartSeries>
419+
</AccumulationChartSeriesCollection>
420+
421+
<AccumulationChartLegendSettings Visible="true" >
422+
</AccumulationChartLegendSettings>
423+
</SfAccumulationChart>
424+
425+
@code {
426+
public class Statistics
427+
{
428+
public string Browser { get; set; }
429+
public double Users { get; set; }
430+
public string Color { get; set; }
431+
}
432+
433+
public List<Statistics> StatisticsDetails = new()
434+
{
435+
new Statistics { Browser = "Chrome", Users = 37, Color = "#f55a65" },
436+
new Statistics { Browser = "UC Browser", Users = 17, Color = "#fcce2c" },
437+
new Statistics { Browser = "iPhone", Users = 19, Color = "#78d6e2" },
438+
new Statistics { Browser = "Others", Users = 4, Color = "#bbd848" },
439+
new Statistics { Browser = "Opera", Users = 11, Color = "#a97bdc" },
440+
new Statistics { Browser = "Android", Users = 12, Color = "#57b879" },
441+
};
442+
443+
}
444+
```
445+
![Legend Template in Blazor Accumulation Chart](images/legend/blazor-accumulation-chart-legend-template.png)
446+
392447
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.
393448

394449
* [Grouping](./grouping)

0 commit comments

Comments
 (0)