Chart Persistence
After a chart has been configured, you can save the setup parameters to a disk file for reuse. The Chart Template system stores the chart configuration in a text file that can be edited. It does not store the data objects. A more powerful persistence strategy is to use standard MFC serialization. The chart’s data objects can be serialized as well as all components.
The chart image can be stored in a disk file with a bitmap, device-independent bitmap, or JPEG format. These formats make it easy to incorporate static chart images into reports and documents.
Chart Template System
All component-based objects are able to write a simple text description of themselves to a disk or memory file. This file may then be used to generate numerous charts with the same configuration. The template system does not save the data held in the chart; however, it does save the contents of any labels used in the chart.
Chart templates may be incorporated into your application as a part of the resource file. When the template loading function is called, it first looks in the resources. If it cannot find the named resource, then the system looks on the disk and loads the template from there.
The template commands are formatted as simple text that you can edit by hand in a text editor. By default, graph templates use the .SGT file extension. To illustrate the chart template, the diagram shown in Figure 17 outlines the various sections of the commands that define the components used in the chart.
Figure 17 – A chart template and the chart it generates
Serialization
The standard MFC serialization procedure is the preferred method of chart reuse. The chart’s data objects can be serialized as well as all components.
The SRGraph class has a Serialize() member that writes or restores all the charts components and data objects to the archive.
The CGraphDoc class has a Serialize() function that calls SRGraph::Serialize() for its SRGraph member.
NOTE >> You cannot serialize data stored using the Structure data model. This prevents this type of data from being copied into the Chart Wizard, which uses serialization to make a local copy of the chart object and its lists.