Skip to content

Commit f1c5217

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

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
26.8 KB
Loading

blazor/chart/legend.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,70 @@ The series [Name](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts
678678

679679
![Hiding Legend Item in Blazor Column Chart](images/legend/blazor-column-chart-hide-legend-item.png)
680680

681+
## Legend Template
682+
683+
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.
684+
685+
To use, add a `LegendItemTemplate` inside any `ChartSeries` 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` is set to false. Templates work with all legend positions, alignments, and paging.
686+
687+
```
688+
@using Syncfusion.Blazor.Charts
689+
690+
<SfChart Title="Olympic Medals">
691+
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category" />
692+
693+
<ChartSeriesCollection>
694+
<ChartSeries DataSource="@MedalDetails" Name="Gold" XName="Country" Width="2" Opacity="1" YName="Gold" Fill="#FFD700" Type="ChartSeriesType.Column">
695+
<LegendItemTemplate>
696+
<div style="font-family:'Segoe UI'; font-size:14px; font-weight:600; padding-right: 5px; color: #FFD700">
697+
<span>Gold</span>
698+
</div>
699+
</LegendItemTemplate>
700+
</ChartSeries>
701+
<ChartSeries DataSource="@MedalDetails" Name="Silver" XName="Country" Width="2" Opacity="1" YName="Silver" Fill="#666666" Type="ChartSeriesType.Column">
702+
<LegendItemTemplate>
703+
<div style="font-family:'Segoe UI'; font-size:14px; font-weight:600; padding-right: 5px; color: #666666">
704+
<span>Silver</span>
705+
</div>
706+
</LegendItemTemplate>
707+
</ChartSeries>
708+
<ChartSeries DataSource="@MedalDetails" Name="Bronze" XName="Country" Width="2" Opacity="1" YName="Bronze" Fill="#CD7F32" Type="ChartSeriesType.Column">
709+
<LegendItemTemplate>
710+
<div style="font-family:'Segoe UI'; font-size:14px; font-weight:600; padding-right: 5px; color: #CD7F32">
711+
<span>Bronze</span>
712+
</div>
713+
</LegendItemTemplate>
714+
</ChartSeries>
715+
</ChartSeriesCollection>
716+
717+
<ChartLegendSettings Visible="true" />
718+
</SfChart>
719+
720+
@code {
721+
722+
public class ChartData
723+
{
724+
public string Country { get; set; }
725+
public double Gold { get; set; }
726+
public double Silver { get; set; }
727+
public double Bronze { get; set; }
728+
}
729+
730+
public List<ChartData> MedalDetails = new List<ChartData>
731+
{
732+
new ChartData{ Country= "USA", Gold=50, Silver=70, Bronze=45 },
733+
new ChartData{ Country="China", Gold=40, Silver= 60, Bronze=55 },
734+
new ChartData{ Country= "Japan", Gold=70, Silver= 60, Bronze=50 },
735+
new ChartData{ Country= "Australia", Gold=60, Silver= 56, Bronze=40 },
736+
new ChartData{ Country= "France", Gold=50, Silver= 45, Bronze=35 },
737+
new ChartData{ Country= "Germany", Gold=40, Silver=30, Bronze=22 },
738+
new ChartData{ Country= "Italy", Gold=40, Silver=35, Bronze=37 },
739+
new ChartData{ Country= "Sweden", Gold=30, Silver=25, Bronze=27 }
740+
};
741+
}
742+
```
743+
![Legend Template in Blazor Column Chart](images/legend/blazor-column-chart-legend-template.png)
744+
681745
N> Refer to our [Blazor Charts](https://www.syncfusion.com/blazor-components/blazor-charts) feature tour page for its groundbreaking feature representations and also explore our [Blazor Chart Example](https://blazor.syncfusion.com/demos/chart/line?theme=bootstrap5) to know various chart types and how to represent time-dependent data, showing trends at equal intervals.
682746

683747
## See also

0 commit comments

Comments
 (0)