Serialization involves the saving of chart properties, usually to disk. Deserialization involves the retrieval of serialized data, followed by the loading of this data into the Chart control.

Serialization enables you to persist and reuse a chart's appearance properties and data. This can save you time when you regularly create charts with the same appearance settings or from a specific data set.

Serialization is accomplished using a ChartSerializer object. You can access it via the Chart.Serializer property.

Format of Serialized Data

The format of serialized data can be either XML or Binary. The advantage of XML is that serialized data is readable, while the advantage of binary is that the serialized data takes less storage space.

Saving and Loading Data

Save chart data by the Save method, and load the the serialized data into a Chart control using the Load method.

When serializing chart data, note that only properties with nvalues are serialized.

Serializable Chart Properties

There are three methods by which chart data can be marked as serializable:

  1. Without explicitly specifying any serializable properties. This causes all chart properties with non-default values (including chart data) to be serialized.
  2. Setting the Content property. This groups the chart properties to be serialized into categories (data, appearance, and so on).
  3. Set the SerializableContent property, which is a comma-separated list of all chart properties to be serialized.

Non-Serializable Chart Properties

Non-serializable properties are set using the NonSerializableContent property. This is a comma-separated listing of all chart properties not to be serialized, and wildcards can be used in the string expression (in the same manner as the SerializableContent property).

Resetting Chart Properties

When chart data is saved, only properties that do not have default values are serialized. This reduces the amount of saved data. Therefore it is possible for a serializable property to not be saved, and during a load operation by default this property will be reset to its default value. Set the ResetWhenLoading property to False if you do not wish to reset non-default data that is serializable but unserialized.