2D Chart for WinForms | ComponentOne
Loading and Saving Charts, Data, and Images / Loading and Saving Chart to a File
In This Topic
    Loading and Saving Chart to a File
    In This Topic

    In C1Chart, each chart can be loaded from and saved to an external XML file using the Save Chart/Load Chart commands from C1Chart’s context menu at design-time or programmatically using any of the following methods:

    The SaveChartAndImagesToFile and LoadChartAndImagesFromFile methods does the same as the SaveChartToFile and LoadChartFromFile methods except that they capture the various background images of the chart elements (chart, header, footer, labels).

    If you only want to save the chart’s data you can do so using the SaveDataToFile and LoadDataFromFile methods of the ChartData object.

    To save just the chart's data to XML, call the SaveDataToFile method, which takes the file's path as a parameter:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    C1Chart1.ChartGroups.Group0.ChartData_
     .SaveDataToFile("C:\ComponentOneDocs\chartdata1.xml")
    

    To write code in C#

    C#
    Copy Code
    c1Chart1.ChartGroups.Group0.ChartData
     .SaveDataToFile("C:\\ComponentOneDocs\\chartdata1.xml");
    

    To load the chart's data back from XML, call the LoadDataFromFile method, which takes the file's path as a parameter:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    C1Chart1.ChartGroups.Group0.ChartData_
     .LoadDataFromFile("C:\ComponentOneDocs\chartdata1.xml")
    

    To write code in C#

    C#
    Copy Code
    C1Chart1.ChartGroups.Group0.ChartData_
     .LoadDataFromFile("C:\ComponentOneDocs\chartdata1.xml")
    

    An in-depth discussion of the structure of the XML file is not covered here, but the file can be opened as a text file and easily dissected.

    See Also