Set Configuration as XML/JSON File

Overview

AnyChart Stock takes two types of configuration files:

These files are identical by their object structure. This article describes and demonstrates how to set an XML or JSON configuration for a chart.

to top

XML Configuration File

Setting an XML configuration file is carried out with the setXMLFile() method. Example:

Read on about the setXMLFile() method in JavaScript API: setXMLFile() method.

Here is a sample demonstrating the functioning of the setXMLFile method:

Online HTML/JavaScript Sample

to top

JSON Configuration File

Setting a JSON configuration file is carried out with the setJSONFile() method. Example:

Read on about the setJSONFile() method in JavaScript API: setJSONFile() method

Here is a sample demonstrating the functioning of the setJSONFile method:

Online HTML/JavaScript Sample

to top

Cross Domain Policy

Methods above tell you how to set configuration as XML or JSON file, parameters for both methods are URLs that point to some file or script on the server and path can be either relative ("../config.xml") or absolute ("http://www.mydomain.com/chart/config.xml").

In some cases loading files may be restricted by Flash Player security policy, these cases are:

Different Domain

If page with the chart is located on one server (http://www.my-domain.com) and config file is located on another domain (http://www.another-domain.com) - you may want to set file:

and this won't work unless you do one of the following things:

Secure Server (https://)

Secure servers may also restrict loading (especially in Internet Explorer), and you may need to:

to top

Avoiding Caching

Important note about set files method in AnyChart Stock: whenever AnyChart Stock engines loads a file it adds a special parameter called XMLCallDate to the URL it requests.

For example, you write:

AnyChart Stock in these cases makes requests that look like:

http://www.mydomain.com/config.xml?XMLCallDate=1278351919656

http://www.mydomain.com/config.php?symb=NYSE&XMLCallDate=1278351919656

This parameter is a timestamp of the current time and is added to avoid config source caching. In some enthronements you may need to add handling of this parameter to your server-side script.

to top

Server-side Scripts as Config Files

Almost in all samples in our documentation we use static XML or JSON files to set initial configuration for charts, but in most of the cases you will need to use server side scripts to generate dynamic config files. AnyChart Stock, of course, allows that, you just need to set script address instead of file address and pass proper parameters to the script, like that:

This technique is demonstrated in this live sample:

Online HTML/JavaScript Sample

to top