Blazorise SVG Chart Animation
Animate SVG chart loading and data updates with C# and Blazor options.
SVG chart animation can be declared with SvgChartAnimation or configured with SvgChartOptions.Animation. Animation targets are grouped by SVG behavior, such as geometry and opacity, and each target can override timing, easing, and load/update behavior. Streaming animations remain configured separately with SvgChartStreamingOptions.Animation.
Examples
Declarative animation
AddSvgChartAnimation inside a chart to animate the first render and subsequent updates.
<Div Flex="Flex.Row" Gap="Gap.Is2" Margin="Margin.Is3.FromBottom"> <Button Color="Color.Primary" Clicked="">Randomize</Button> <Button Color="Color.Light" Clicked="">Reset</Button> </Div> <SvgColumnChart TItem="MonthlyRevenue" Items="" Options=""> <SvgChartAnimation Enabled Duration="@TimeSpan.FromMilliseconds( 500 )" Easing="SvgChartAnimationEasing.EaseOut" Geometry="" Opacity="" /> <SvgChartTitle Title='@("Animated revenue")' Subtitle='@("Columns animate on load and update")' /> <SvgChartLegend Position="SvgChartLegendPosition.Bottom" /> <SvgChartTooltip Enabled /> <SvgChartCategoryAxis Value="@( item => item.Month )" /> <SvgChartValueAxis BeginAtZero TickCount="6" /> <SvgColumnSeries Name="Revenue" Value="@( item => item.Revenue )" Color="Color.Primary" BorderRadius="4" /> <SvgColumnSeries Name="Expenses" Value="@( item => item.Expenses )" Color="Color.Info" BorderRadius="4" /> </SvgColumnChart>
@code { private readonly Random random = new( 42 ); private readonly SvgChartOptions options = new() { Height = 360, Legend = new() { Position = SvgChartLegendPosition.Bottom }, }; private readonly SvgChartGeometryAnimationOptions geometryAnimation = new() { Duration = TimeSpan.FromMilliseconds( 650 ), AnimatePosition = true, AnimateSize = true }; private readonly SvgChartOpacityAnimationOptions opacityAnimation = new() { Duration = TimeSpan.FromMilliseconds( 800 ), Delay = TimeSpan.FromMilliseconds( 50 ), From = 0.1 }; private List<MonthlyRevenue> revenue = CreateRevenue(); private void Randomize() { foreach ( var item in revenue ) { item.Revenue = Math.Max( 30, item.Revenue + random.Next( -16, 17 ) ); item.Expenses = Math.Max( 20, item.Expenses + random.Next( -12, 13 ) ); } } private void Reset() { revenue = CreateRevenue(); } private static List<MonthlyRevenue> CreateRevenue() { return [ new() { Month = "Jan", Revenue = 68, Expenses = 42 }, new() { Month = "Feb", Revenue = 74, Expenses = 46 }, new() { Month = "Mar", Revenue = 91, Expenses = 52 }, new() { Month = "Apr", Revenue = 86, Expenses = 49 }, new() { Month = "May", Revenue = 103, Expenses = 61 }, ]; } private sealed class MonthlyRevenue { public string Month { get; set; } public double Revenue { get; set; } public double Expenses { get; set; } } }
Options animation
Configure animation throughSvgChartOptions.Animation when options are built in C#.
<Div Flex="Flex.Row" Gap="Gap.Is2" Margin="Margin.Is3.FromBottom"> <Button Color="Color.Primary" Clicked="">Randomize</Button> <Button Color="Color.Light" Clicked="">Reset</Button> </Div> <SvgLineChart TItem="TrafficSample" Items="" Options=""> <SvgChartTitle Title='@("Traffic trend")' Subtitle='@("Path and point animation configured from options")' /> <SvgChartLegend Position="SvgChartLegendPosition.Bottom" /> <SvgChartTooltip Enabled /> <SvgChartCategoryAxis Value="@( item => item.Day )" /> <SvgChartValueAxis BeginAtZero TickCount="6" /> <SvgLineSeries Name="Desktop" Value="@( item => item.Desktop )" Color="Color.Primary" MarkerRadius="4" /> <SvgLineSeries Name="Mobile" Value="@( item => item.Mobile )" Color="Color.Success" MarkerRadius="4" /> </SvgLineChart>
@code { private readonly Random random = new( 11 ); private readonly SvgChartOptions options = new() { Height = 360, Legend = new() { Position = SvgChartLegendPosition.Bottom }, Animation = new() { Enabled = true, Duration = TimeSpan.FromMilliseconds( 600 ), Easing = SvgChartAnimationEasing.EaseInOut, Geometry = new() { Duration = TimeSpan.FromMilliseconds( 450 ), }, Opacity = new() { From = 0.15, }, Path = new() { Enabled = true, Duration = TimeSpan.FromMilliseconds( 700 ), }, }, }; private List<TrafficSample> samples = CreateSamples(); private void Randomize() { foreach ( var sample in samples ) { sample.Desktop = Math.Clamp( sample.Desktop + random.Next( -14, 15 ), 35, 95 ); sample.Mobile = Math.Clamp( sample.Mobile + random.Next( -12, 13 ), 30, 90 ); } } private void Reset() { samples = CreateSamples(); } private static List<TrafficSample> CreateSamples() { return [ new() { Day = "Mon", Desktop = 54, Mobile = 45 }, new() { Day = "Tue", Desktop = 72, Mobile = 45 }, new() { Day = "Wed", Desktop = 75, Mobile = 61 }, new() { Day = "Thu", Desktop = 55, Mobile = 61 }, new() { Day = "Fri", Desktop = 75, Mobile = 73 }, new() { Day = "Sat", Desktop = 85, Mobile = 80 }, ]; } private sealed class TrafficSample { public string Day { get; set; } public double Desktop { get; set; } public double Mobile { get; set; } } }
API
Parameters
SvgChartAnimation
| Parameter | Description | Type | Default |
|---|---|---|---|
AnimateOnLoad |
Defines whether chart elements animate when the chart first renders. |
bool | true |
AnimateOnUpdate |
Defines whether chart elements animate when chart data or options update. |
bool | true |
Delay |
Defines the delay before chart animations start. |
TimeSpan | TimeSpan.Zero |
Duration |
Defines the duration used by chart animations. |
TimeSpan | TimeSpan.FromMilliseconds( 400 ) |
Easing |
Defines the easing function used by chart animations. Possible values: |
SvgChartAnimationEasing | SvgChartAnimationEasing.EaseOut |
Enabled |
Defines whether general chart animations are enabled. |
bool | true |
Geometry |
Defines geometry animation options. |
SvgChartGeometryAnimationOptions | new() |
Opacity |
Defines opacity animation options. |
SvgChartOpacityAnimationOptions | new() |
Path |
Defines path animation options. |
SvgChartPathAnimationOptions | new() |
Stroke |
Defines stroke animation options. |
SvgChartStrokeAnimationOptions | new() |
Transform |
Defines transform animation options. |
SvgChartTransformAnimationOptions | new() |
SvgChartAnimationOptions
| Parameter | Description | Type | Default |
|---|---|---|---|
AnimateOnLoad |
Defines whether chart elements animate when the chart first renders. |
bool | true |
AnimateOnUpdate |
Defines whether chart elements animate when chart data or options update. |
bool | true |
Delay |
Defines the delay before chart animations start. |
TimeSpan | TimeSpan.Zero |
Duration |
Defines the duration used by chart animations. |
TimeSpan | TimeSpan.FromMilliseconds( 400 ) |
Easing |
Defines the easing function used by chart animations. Possible values: |
SvgChartAnimationEasing | SvgChartAnimationEasing.EaseOut |
Enabled |
Defines whether general chart animations are enabled. |
bool | false |
Geometry |
Defines geometry animation options. |
SvgChartGeometryAnimationOptions | new() |
Opacity |
Defines opacity animation options. |
SvgChartOpacityAnimationOptions | new() |
Path |
Defines path animation options. |
SvgChartPathAnimationOptions | new() |
Stroke |
Defines stroke animation options. |
SvgChartStrokeAnimationOptions | new() |
Transform |
Defines transform animation options. |
SvgChartTransformAnimationOptions | new() |
SvgChartAnimationTargetOptions
| Parameter | Description | Type | Default |
|---|---|---|---|
AnimateOnLoad |
Defines whether the target animates when the chart first renders. When not set, the chart animation setting is used. |
bool? | null |
AnimateOnUpdate |
Defines whether the target animates when chart data or options update. When not set, the chart animation setting is used. |
bool? | null |
Delay |
Defines the target-specific animation delay. When not set, the chart animation delay is used. |
TimeSpan? | null |
Duration |
Defines the target-specific animation duration. When not set, the chart animation duration is used. |
TimeSpan? | null |
Easing |
Defines the target-specific animation easing. When not set, the chart animation easing is used. |
SvgChartAnimationEasing? | null |
Enabled |
Defines whether animations for the target are enabled. |
bool | true |
SvgChartGeometryAnimationOptions
| Parameter | Description | Type | Default |
|---|---|---|---|
AnimatePosition |
Defines whether position attributes such as x, y, cx, and cy are animated. |
bool | true |
AnimateSize |
Defines whether size attributes such as width, height, and radius are animated. |
bool | true |
SvgChartOpacityAnimationOptions
| Parameter | Description | Type | Default |
|---|---|---|---|
From |
Defines the opacity value used as the animation start value. |
double | 0 |
SvgChartStrokeAnimationOptions
| Parameter | Description | Type | Default |
|---|---|---|---|
AnimateDashPattern |
Defines whether stroke dash pattern changes may be animated by renderers that support stroke animations. |
bool | true |
AnimateWidth |
Defines whether stroke width changes may be animated by renderers that support stroke animations. |
bool | true |
SvgChartTransformAnimationOptions
| Parameter | Description | Type | Default |
|---|---|---|---|
ScaleFrom |
Defines the scale value used by renderers that support transform scale animations. |
double | 0.95 |
ScaleTo |
Defines the scale target value used by renderers that support transform scale animations. |
double | 1 |
SvgChartPathAnimationOptions
| Parameter | Description | Type | Default |
|---|---|---|---|
AnimateLength |
Defines whether path length changes may be animated by renderers that support path animations. |
bool | true |
AnimateShape |
Defines whether path shape changes may be animated by renderers that support path animations. |
bool | true |
Methods
SvgChartAnimation
| Method | Description | Return | Parameters |
|---|---|---|---|
Render |
Renders the plugin SVG content into the chart. | void | SvgChartPluginRenderContext context, RenderTreeBuilder builder, int sequence |