Skip to content

Commit 6da88a5

Browse files
committed
998039: Added UG documentation for Stock chart legend template.
1 parent 7fea9f0 commit 6da88a5

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
38.5 KB
Loading

blazor/stock-chart/legend.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,3 +561,58 @@ The series [Name](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts
561561
```
562562

563563
![Blazor Stock Chart hiding legend item](images/blazor-stock-chart-hidding-legend.png)
564+
565+
## Legend Template
566+
567+
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.
568+
569+
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.
570+
571+
```
572+
@using Syncfusion.Blazor.Charts
573+
574+
<SfStockChart Title="AAPL Stock Price" SelectionMode="SelectionMode.Series">
575+
<StockChartLegendSettings Visible="true" ToggleVisibility="true">
576+
</StockChartLegendSettings>
577+
<StockChartSeriesCollection>
578+
<StockChartSeries DataSource="@StockDetails" Type="ChartSeriesType.Line" XName="Date" High="High" Low="Low" Open="Open" Close="Close" Name="Apple Stock Price" Fill="red">
579+
<LegendItemTemplate>
580+
<div style="font-weight:800; font-family:'Segoe UI'; color: red">
581+
<span>Apple Stock Price</span>
582+
</div>
583+
</LegendItemTemplate>
584+
</StockChartSeries>
585+
<StockChartSeries DataSource="@StockDetails" Type="ChartSeriesType.Spline" XName="Date" High="High" Low="Low" Open="Open" Close="Close" Name="Google Stock Price" Fill="cornflowerblue">
586+
<LegendItemTemplate>
587+
<div style="font-weight:800; font-family:'Segoe UI'; color: cornflowerblue">
588+
<span>Google Stock Price</span>
589+
</div>
590+
</LegendItemTemplate>
591+
</StockChartSeries>
592+
</StockChartSeriesCollection>
593+
</SfStockChart>
594+
595+
@code {
596+
public class ChartData
597+
{
598+
public DateTime Date { get; set; }
599+
public Double Open { get; set; }
600+
public Double Low { get; set; }
601+
public Double Close { get; set; }
602+
public Double High { get; set; }
603+
public Double Volume { get; set; }
604+
}
605+
606+
public List<ChartData> StockDetails = new List<ChartData>
607+
{
608+
new ChartData { Date = new DateTime(2012, 04, 02), Open = 85.9757, High = 90.6657, Low = 85.7685, Close = 90.5257, Volume = 660187068 },
609+
new ChartData { Date = new DateTime(2012, 04, 09), Open = 89.4471, High = 92, Low = 86.2157, Close = 86.4614, Volume = 912634864 },
610+
new ChartData { Date = new DateTime(2012, 04, 16), Open = 87.1514, High = 88.6071, Low = 81.4885, Close = 81.8543, Volume = 1221746066 },
611+
new ChartData { Date = new DateTime(2012, 04, 23), Open = 81.5157, High = 88.2857, Low = 79.2857, Close = 86.1428, Volume = 965935749 },
612+
new ChartData { Date = new DateTime(2012, 04, 30), Open = 85.4, High = 85.4857, Low = 80.7385, Close = 80.75, Volume = 615249365 }
613+
};
614+
}
615+
```
616+
![Blazor Stock Chart legend template](images/blazor-stock-chart-legend-template.png)
617+
618+

0 commit comments

Comments
 (0)