docs/shared/chart.md
{{~ if name != "Cartesian chart control" }}
:::info
This section uses the end ~}}CartesianChart control, but it works the same in the {{ name | to_title_case_no_spaces }} control.
:::
{{
Defines the animations speed of all the [chart elements]({{ website_url }}/api/{{ version }}/LiveChartsCore.Kernel.IChartElement-1) (axes, series, sections).
{{~ if xaml ~}}
<pre><code><lvc:CartesianChart Series="{Binding Series}" AnimationsSpeed="00:00:00.500"> <!-- 500 milliseconds --> <!-- mark --> </lvc:CartesianChart></code></pre>{{~ end ~}}
{{~ if blazor ~}}
<pre><code><lvc:CartesianChart Series="{Binding Series}" AnimationsSpeed="speed"> <!-- mark --> </lvc:CartesianChart></code></pre> <pre><code>private TimeSpan speed = TimeSpan.FromMilliseconds(500);</code></pre>{{~ end ~}}
{{~ if winforms ~}}
<pre><code>cartesianChart1.AnimationsSpeed = TimeSpan.FromMilliseconds(500);</code></pre>{{~ end ~}}
{{~ if name != "Cartesian chart control" }}
:::info
This section uses the end ~}}CartesianChart control, but it works the same in the {{ name | to_title_case_no_spaces }} control.
:::
{{
This property defines the way the shapes in the chart animate, in other words it controls the way the [IMotionProperties]({{ website_url }}/api/{{ version }}/LiveChartsCore.Motion.IMotionProperty) of all the [chart elements]({{ website_url }}/api/{{ version }}/LiveChartsCore.Kernel.IChartElement-1) (axes, series, sections) in the chart move from a state 'A' to state 'B'.
The property is of type Func<float, float>, it means that it is a function that takes a float argument (the time elapsed from 0 to 1),
and returns float value as the result (the progress of the animation from 0 to 1), you can learn more about easing curves at
this article.
{{~ if xaml ~}}
<pre><code><Container xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:lvcore="clr-namespace:LiveChartsCore;assembly=LiveChartsCore"> <!-- import the core ns --> <!-- mark --> <lvc:CartesianChart Series="{Binding Series}" AnimationsSpeed="00:00:00.500" EasingFunction="{Binding Source={x:Static lvcore:EasingFunctions.BounceOut}}"> <!-- mark --> </lvc:CartesianChart> </Container></code></pre>{{~ end ~}}
{{~ if blazor ~}}
<pre><code><lvc:CartesianChart Series="{Binding Series}" AnimationsSpeed="speed" EasingFunction=""> <!-- mark --> </lvc:CartesianChart></code></pre> <pre><code>private Func<float, float> easing = LiveChartsCore.EasingFunctions.BounceOut; // mark</code></pre>{{~ end ~}}
{{~ if winforms ~}}
<pre><code>cartesianChart1.EasingFunction = LiveChartsCore.EasingFunctions.BounceOut;</code></pre>{{~ end ~}}
Now the chart will animate following the BounceOut curve.
Now try the LiveChartsCore.EasingFunctions.Lineal function, it will animate things lineally as the time elapses.
Finally you can also build your own function:
{{~ if xaml ~}}
<pre><code>public Func<float, float> Easing { get; set; } = time => time * time; // mark</code></pre> <pre><code><Control xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <lvc:CartesianChart Series="{Binding Series}" AnimationsSpeed="00:00:00.500" EasingFunction="{Binding Easing}"> <!-- mark --> </lvc:CartesianChart></code></pre>{{~ end ~}}
{{~ if blazor ~}}
<pre><code><lvc:CartesianChart Series="{Binding Series}" AnimationsSpeed="speed" EasingFunction="easing"> <!-- mark --> </lvc:CartesianChart></code></pre> <pre><code>private Func<float, float> easing = time => time * time; // mark</code></pre>{{~ end ~}}
{{~ if winforms ~}}
<pre><code>cartesianChart1.EasingFunction = time => time * time;</code></pre>{{~ end ~}}
The library also provides some builders based on d3-ease easing curves.
<pre><code>Func<float, float> easingCurve = LiveChartsCore.EasingFunctions.BuildCustomBackOut(0.8f); Func<float, float> easingCurve = LiveChartsCore.EasingFunctions.BuildCustomElasticOut(0.8f, 1.1f); // there are more builders, check them out all, they start with Build{ function }({ args })</code></pre>{{~ if name != "Cartesian chart control" }}
:::info
This section uses the end ~}}CartesianChart control, but it works the same in the {{ name | to_title_case_no_spaces }} control.
:::
{{
Setting the EasingFunction to null disables animations.
{{~ if xaml ~}}
<pre><code><lvc:CartesianChart EasingFunction="{x:Null}"> <!-- mark --> </lvc:CartesianChart></code></pre>{{~ end ~}}
{{~ if blazor ~}}
<pre><code><lvc:CartesianChart EasingFunction="null"> <!-- mark --> </lvc:CartesianChart></code></pre>{{~ end ~}}
{{~ if winforms ~}}
<pre><code>cartesianChart1.EasingFunction = null; // mark</code></pre>{{~ end ~}}
:::info
Disabling animations will not improve performance drastically: if you come from LiveCharts 0.x version then
maybe you are thinking that disabling animations will improve the performance of the library, in most of the cases
that is not true, animations are not the bottleneck in performance in LiveCharts 2.x, normally you need to
clean your code somewhere else, not here, plus we put a lot of effort building the animations of the library, please
just do not disable them 😭, instead try to make them run faster, animating data visualization normally brings
an excellent user experience.
:::
{{~ if name != "Cartesian chart control" }}
:::info
This section uses the end ~}}CartesianChart control, but it works the same in the {{ name | to_title_case_no_spaces }} control.
:::
{{
Defines the distance from the axes (or edge of the chart if there is no axis) to the draw margin area.
{{~ if xaml ~}}
<pre><code>// Notice the constructor of the Margin class has multiple overloads // {{ website_url }}/api/{{ version }}/LiveChartsCore.Measure.Margin public LiveChartsCore.Measure.Margin Margin { get; set; } = new LiveChartsCore.Measure.Margin(100); // mark</code></pre> <pre><code><lvc:CartesianChart Series="{Binding Series}" DrawMargin="{Binding Margin}"> <!-- mark --> </lvc:CartesianChart></code></pre>{{~ end ~}}
{{~ if blazor ~}}
<pre><code><lvc:CartesianChart Series="{Binding Series}" AnimationsSpeed="speed" DrawMargin="margin"> <!-- mark --> </lvc:CartesianChart></code></pre> <pre><code>// Notice the constructor of the Margin class has multiple overloads // {{ website_url }}/api/{{ version }}/LiveChartsCore.Measure.Margin private LiveChartsCore.Measure.Margin margin = new LiveChartsCore.Measure.Margin(100); // mark</code></pre>{{~ end ~}}
{{~ if winforms ~}}
<pre><code>// Notice the constructor of the Margin class has multiple overloads // {{ website_url }}/api/{{ version }}/LiveChartsCore.Measure.Margin cartesianChart1.DrawMargin = new LiveChartsCore.Measure.Margin(100);</code></pre>{{~ end ~}}