Chart for Silverlight Top Tips

The following top tips for Chart for Silverlight will help you when you use the C1Chart control.

Tip 1: Use the BeginUpdate()/EndUpdate methods to improve performance

When performing a massive update of the chart properties or the data values, put the update code inside a BeginUpdate()/EndUpdate() block.

This improves performance since the redrawing occurs only once after a call of the EndUpdate() method.

For example:

      Visual Basic

      C#

Tip 2: Use the line or area chart type for large data arrays

The line and area charts provide the best performance when you have a lots of data values.

To get better performance, enable built-in optimization for large data by setting the attached property, LineAreaOptions.OptimizationRadius. For example:

      Visual Basic

      C#

It's recommended you use small values 1.0 - 2.0 as radius. A larger value may affect the accuracy of the plot.

Tip 3: Update the appearance and behavior of a plot element using the DataSeries.PlotElementLoaded event

When any plot element (bar,column,pie, etc) is loaded it fires the PlotElementLoaded event. During this event you have access to the plot element properties as well as to the corresponding data point.

The following code sets the colors of points depending on its y-value. For example:

      Visual Basic

      C#

Tip 4: Data point labels and tooltips

To create a data point label or tooltip, you should set the data template for the PointLabelTemplate or PointTooltipTemplate property.

The following sample code shows the index for each data point.

XAML:

<c1chart:C1Chart Name="c1Chart1" ChartType="XYPlot">

  <c1chart:C1Chart.Data>

    <c1chart:ChartData>

      <!-- source collection -->

      <c1chart:ChartData.ItemsSource>

        <PointCollection>

          <Point X="1" Y="1" />

          <Point X="2" Y="2" />

          <Point X="3" Y="3" />

          <Point X="4" Y="2" />

          <Point X="5" Y="1" />

        </PointCollection>

      </c1chart:ChartData.ItemsSource>

 

      <c1chart:XYDataSeries SymbolSize="16,16"

        XValueBinding="{Binding X}" ValueBinding="{Binding Y}">

        <c1chart:XYDataSeries.PointLabelTemplate>

          <DataTemplate>

            <!-- display point index at the center of point symbol  -->

            <TextBlock c1chart:PlotElement.LabelAlignment="MiddleCenter"

                       Text="{Binding PointIndex}" />

          </DataTemplate>

        </c1chart:XYDataSeries.PointLabelTemplate>

      </c1chart:XYDataSeries>

    </c1chart:ChartData>

  </c1chart:C1Chart.Data>

</c1chart:C1Chart>

The data context of element created from the template is set to the instance of DataPoint class which contains information about the corresponding data point.

Tip 5: Save chart as image

The following method saves chart image as png-file.

      Visual Basic

      C#

Tip 6: Printing chart

The following code prints the specified chart on the default printer with the default settings. For example:

      Visual Basic

      C#

Tip 7: Mixing Cartesian chart types

You can easily mix different chart types on the same Cartesian plot using the ChartType property.

The following code creates three data series: the first is area, the second is step, and the third has the default chart type (line).

      Visual Basic

      C#


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.