Set Configuration as XML/JSON File
- Overview
- XML Configuration File
- JSON Configuration File
- Cross Domain Policy
- Avoiding Caching
- Server-side Scripts as Config Files
Overview
AnyChart Stock takes two types of configuration files:
- XML
- JSON
These files are identical by their object structure. This article describes and demonstrates how to set an XML or JSON configuration for a chart.
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:
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:
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:
- Configure cross domain policy file on one domain to allow access to files from another domain as described at adobe.com: Cross-domain policy file specification.
- Create proxy script on your domain that will load files from another domain using server to server communication.
Secure Server (https://)
Secure servers may also restrict loading (especially in Internet Explorer), and you may need to:
- Configure cross domain policy file on one domain to allow access to files from another domain as described at: Cross-domain policy file specification.
- Make your file/script to be sent with "Pragma: cache" header (which is usually "Pragma: no-cache" be default). See details at: Adobe TechNote
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.
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: