6.2 KiB
layout | title | description | platform | control | documentation |
---|---|---|---|---|---|
post | Performance in Xamarin Charts control | Syncfusion | Learn here all about Performance support in Syncfusion Xamarin Charts (SfChart) control, its elements and more. | xamarin | Chart | ug |
Performance in Xamarin Charts (SfChart)
Following are the key points that can be used to boost the performance of the chart when there is a need to plot high volume data.
- When there are large number of points to load in line series, you can use
FastLineSeries
series instead ofLineSeries
. To renderer a fast line chart, create an instance ofFastLineSeries
and add to theSeries
collection property ofSfChart
.
{% tabs %}
{% highlight xaml %}
chart:SfChart ...
<chart:FastLineSeries ItemsSource ="{Binding Data}" XBindingPath="XValue" YBindingPath="YValue"/>
</chart:SfChart>
{% endhighlight %}
{% highlight c# %}
SfChart chart = new SfChart(); ...
FastLineSeries fastLineSeries = new FastLineSeries() {
ItemsSource = Data,
XBindingPath = "XValue",
YBindingPath = "YValue"
};
chart.Series.Add(fastLineSeries);
{% endhighlight %}
{% endtabs %}
N>If you have minimal set of data points, the recommended approach is to use normal line series to visualize those data using line chart. Because the normal line series has provisions to customize the color and shape of individual line.
-
Instead of enabling data markers and labels when there are large number of data points, you can use
Trackball
to view the point information. -
The default stroke width of the
FastLineSeries
is 2, reducing this to 1 will improve the performance. Refer the following code snippet to configure the stroke width of FastLineSeries.
{% tabs %}
{% highlight xaml %}
chart:SfChart ...
<chart:FastLineSeries ItemsSource ="{Binding Data}" XBindingPath="XValue" YBindingPath="YValue" StrokeWidth="1"/>
</chart:SfChart>
{% endhighlight %}
{% highlight c# %}
SfChart chart = new SfChart(); ...
FastLineSeries fastLineSeries = new FastLineSeries() {
ItemsSource = Data,
XBindingPath = "XValue",
YBindingPath = "YValue",
StrokeWidth = 1
};
chart.Series.Add(fastLineSeries);
{% endhighlight %}
{% endtabs %}
-
When the underlying data object implements INotifyPropertyChanged, you need to enable the
ListenPropertyChange
property of the series, to make the chart listen to the property changes of your data object. However enabling this property registers PropertyChanged event of every object in the data source. Due to this, chart’s loading time is affected when there are a large number of points. By default,ListenPropertyChange
is set to false in order to avoid the event registration unnecessarily. -
Whenever there is a new data point is added to the
ItemsSource
property ofChartSeries
, the chart will be refreshed with new data point if theItemsSource
property containsObservableCollection
. In order to avoid the chart rendering for each update inItemsSource
, you can suspend the chart usingSuspendSeriesNotification
method of chart and theResumeSeriesNotification
should be called once the required data points are added to the collection and the chart should be refreshed with data points that have been added between these two method calls.
{% tabs %}
{% highlight c# %}
Chart.SuspendSeriesNotification();
// ...
// Add the data points to ItemsSource property.
// ...
Chart.ResumeSeriesNotification();
{% endhighlight %}
{% endtabs %}
Similarly, you can use SuspendNotification
and ResumeNotification
methods of ChartSeries
to suspend and resume the update of the respective series.
{% tabs %}
{% highlight c# %}
series.SuspendNotification();
// ...
// Add the data points to ItemsSource property.
// ...
series.ResumeNotification();
{% endhighlight %}
{% endtabs %}
N> You can refer to our Xamarin Charts feature tour page for its groundbreaking feature representations. You can also explore our Xamarin.Forms Charts example to knows various chart types and how to easily configured with built-in support for creating stunning visual effects.