Serialization in WPF Charts (SfChart)

14 Jul 20213 minutes to read

SfChart provides the support for serializing and deserializing control. This section explains on how to serialize and deserialize SfChart.

Method Name Description
Serialize() Serialize the control and saves as the XML file in the parent folder.
Serialize(string filePath) Serialize the control and saves as the XML file in the given file path.
Serialize(Stream stream) Serialize the control and saves as the XML file in the given stream.
Deserialize() Deserialize the XML file from the parent folder and returns the SfChart control object.
Deserialize(string filePath) Deserialize the XML file from the given file path and returns the SfChart control object.
Deserialize(Stream stream) Deserialize the XML file from the given stream and returns the SfChart control object.
<Grid >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="350" />
            <ColumnDefinition Width="350" />
        </Grid.ColumnDefinitions>
        
        <!--Serialize-->
        <chart:SfChart Grid.Column="0" Margin="10" x:Name="chart">

            <chart:SfChart.PrimaryAxis>
                <chart:CategoryAxis />
            </chart:SfChart.PrimaryAxis>
            
            <chart:SfChart.SecondaryAxis>
                <chart:NumericalAxis />
            </chart:SfChart.SecondaryAxis>
            
            <chart:ColumnSeries ItemsSource="{Binding CategoricalDatas}" XBindingPath="Category"
                                YBindingPath="Value"  EnableAnimation="True">
                <chart:ColumnSeries.AdornmentsInfo>
                    <chart:ChartAdornmentInfo ShowLabel="True" ShowMarker="True" Symbol="Ellipse" Foreground="White"/>
                </chart:ColumnSeries.AdornmentsInfo>
            </chart:ColumnSeries>
        </chart:SfChart>

         <!--Assign the DeSerialize Chart-->
        <chart:SfChart Grid.Column="1" x:Name="deserializedChart"/>
 
    </Grid>
//Action to Serialize the Chart
       private void Button_Click(object sender, RoutedEventArgs e)
        {
            chart.Serialize();         
        }

        //Action to Deserialize the Chart
        private void Load_Click(object sender, RoutedEventArgs e)
        {
            deserializedChart = (SfChart)chart.Deserialize();
        }

WPF Chart Serialization

NOTE

You can refer to our WPF Charts feature tour page for its groundbreaking feature representations. You can also explore our WPF Charts example to knows various chart types and how to easily configured with built-in support for creating stunning visual effects.