Blazorise SVG Chart Trendlines
Calculate and render trendlines directly in SVG charts.
SVG chart trendlines can be declared as child components with SvgChartTrendline or supplied through SvgChartOptions.Trendlines. Each trendline targets a source series by name.
Examples
Declarative trendline
Add a trendline to a chart by declaringSvgChartTrendline inside the chart.
<SvgColumnChart TItem="MonthlySales" Items="" Options=""> <SvgChartTitle Title='@("Monthly revenue")' Subtitle='@("Linear trendline declared in markup")' /> <SvgChartLegend Position="SvgChartLegendPosition.Bottom" /> <SvgChartTooltip Enabled /> <SvgChartTrendline SeriesName="Revenue" Color="Color.Danger" StrokeWidth="2.5" DashPattern="8 5" /> <SvgChartCategoryAxis Value="@( item => item.Month )" /> <SvgChartValueAxis BeginAtZero TickCount="6" /> <SvgColumnSeries Name="Revenue" Value="@( item => item.Revenue )" Color="Color.Primary" BorderRadius="4" /> </SvgColumnChart>
@code { private readonly SvgChartOptions options = new() { Height = 360, Legend = new() { Position = SvgChartLegendPosition.Bottom }, }; private readonly List<MonthlySales> sales = [ new() { Month = "Jan", Revenue = 82 }, new() { Month = "Feb", Revenue = 88 }, new() { Month = "Mar", Revenue = 93 }, new() { Month = "Apr", Revenue = 91 }, new() { Month = "May", Revenue = 104 }, new() { Month = "Jun", Revenue = 112 }, new() { Month = "Jul", Revenue = 118 }, ]; private sealed class MonthlySales { public string Month { get; set; } public double Revenue { get; set; } } }
Options trendlines
Configure multiple trendlines throughSvgChartOptions.Trendlines.
<SvgLineChart TItem="AcquisitionSample" Items="" Options=""> <SvgChartTitle Title='@("Acquisition channels")' Subtitle='@("Trendlines configured from options")' /> <SvgChartLegend Position="SvgChartLegendPosition.Bottom" /> <SvgChartTooltip Enabled /> <SvgChartCategoryAxis Value="@( item => item.Month )" /> <SvgChartValueAxis BeginAtZero TickCount="6" /> <SvgLineSeries Name="Organic" Value="@( item => item.Organic )" Color="Color.Primary" MarkerRadius="4" /> <SvgLineSeries Name="Paid" Value="@( item => item.Paid )" Color="Color.Success" MarkerRadius="4" /> </SvgLineChart>
@code { private readonly SvgChartOptions options = new() { Height = 360, Legend = new() { Position = SvgChartLegendPosition.Bottom }, Trendlines = [ new() { SeriesName = "Organic", Name = "Organic trend", Color = Color.Primary, StrokeWidth = 2, DashPattern = "8 5", }, new() { SeriesName = "Paid", Name = "Paid trend", Color = Color.Success, StrokeWidth = 2, DashPattern = "4 4", }, ], }; private readonly List<AcquisitionSample> samples = [ new() { Month = "Jan", Organic = 46, Paid = 31 }, new() { Month = "Feb", Organic = 52, Paid = 38 }, new() { Month = "Mar", Organic = 55, Paid = 42 }, new() { Month = "Apr", Organic = 61, Paid = 45 }, new() { Month = "May", Organic = 67, Paid = 52 }, new() { Month = "Jun", Organic = 72, Paid = 57 }, ]; private sealed class AcquisitionSample { public string Month { get; set; } public double Organic { get; set; } public double Paid { get; set; } } }
API
Parameters
SvgChartTrendline
| Parameter | Description | Type | Default |
|---|---|---|---|
Color |
Defines the trendline color. Use a Blazorise theme color, or pass a CSS color value such as |
Color | null |
DashPattern |
Defines the trendline stroke dash pattern. |
string | "6 4" |
Name |
Defines the trendline name. |
string | |
Opacity |
Defines the trendline opacity. |
double | 0.85 |
Order |
Defines the trendline rendering order among other trendlines. Lower values are rendered first, behind higher values. |
int? | null |
SeriesName |
Defines the source series name used to calculate the trendline. |
string | |
StrokeWidth |
Defines the trendline stroke width. |
double | 2 |
Type |
Defines the trendline calculation type. Possible values: |
SvgChartTrendlineType | SvgChartTrendlineType.Linear |
Visible |
Defines whether the trendline is visible. |
bool | true |
SvgChartTrendlineOptions
| Parameter | Description | Type | Default |
|---|---|---|---|
Color |
Defines the trendline color. Use a Blazorise theme color, or pass a CSS color value such as |
Color | null |
DashPattern |
Defines the trendline stroke dash pattern. |
string | "6 4" |
Name |
Defines the trendline name. |
string | |
Opacity |
Defines the trendline opacity. |
double | 0.85 |
Order |
Defines the trendline rendering order among other trendlines. Lower values are rendered first, behind higher values. |
int? | null |
SeriesName |
Defines the source series name used to calculate the trendline. |
string | |
StrokeWidth |
Defines the trendline stroke width. |
double | 2 |
Type |
Defines the trendline calculation type. Possible values: |
SvgChartTrendlineType | SvgChartTrendlineType.Linear |
Visible |
Defines whether the trendline is visible. |
bool | true |
Methods
SvgChartTrendline
| Method | Description | Return | Parameters |
|---|---|---|---|
Render |
Renders the plugin SVG content into the chart. | void | SvgChartPluginRenderContext context, RenderTreeBuilder builder, int sequence |