Loading XML File

Overview

Ability to load XML files and deserialize directly from XML files are the features Data Adapter provides.

To work with the features Data Adapter provides you need to plug it in along with AnyChart Library:

<!-- Include the data adapter -->
<script src="https://cdn.anychart.com/js/v7/data-adapter.min.js"></script>

You can load Data from XML into AnyChart without the help of Data Adapter but if you want to load a file you can do it using the data adapter and the loadXmlFile() and create charts from files with fromXmlFile() method.

Loading File with loadXmlFile method

Using loadXmlFile() method is as easy as this, you can put data in AnyChart XML data format into XML file:

<?xml version="1.0" encoding="utf-8"?>
<anychart>
    <data>
        <point name="Eyeshadows" value="249980"/>
        <point name="Eyeliner" value="213210"/>
        <point name="Eyebrow pencil" value="170670"/>
        <point name="Nail polish" value="143760"/>
        <point name="Pomade" value="128000"/>
        <point name="Lip gloss" value="110430"/>
        <point name="Mascara" value="102610"/>
        <point name="Foundation" value="94190"/>
        <point name="Rouge" value="80540"/>
        <point name="Powder" value="53540"/>
    </data>
</anychart>

And the load and use such file:

anychart.data.loadXmlFile("https://cdn.anychart.com/charts-data/data_xml.xml", function (data) {
	// create a chart and set loaded data
    chart = anychart.bar(data);

    chart.title("Load XML data and create a chart");
    chart.container("container");
    chart.draw();
});

Here is a live sample:

Playground

This method also allows to handle loading errors, changing sending method, adding headers, setting timeout interval, and sending credentials, see all available parameters in loadXmlFile() API description.

You can use this method to load anything else too.

Deserializing from XML File

With fromXmlFile() method you can deserialize a chart directly from a file with chart settings and data in AnyChart XML format:

// Create a chart from XML file
anychart.fromXmlFile("https://cdn.anychart.com/config-samples/line-chart.xml", function (chart) {
	// set additional settings
    chart.title("Create a chart from XML config");

    // display a chart
    chart.container("container");
    chart.draw();
});

Here is a live sample:

Playground

This method also allows to handle loading errors, changing sending method, adding headers, setting timeout interval, and sending credentials, see all available parameters in fromXmlFile() API description.

You are looking at an outdated v7 version of this document. Switch to the v8 version to see the up to date information.