Archive for June, 2008

Using AnyChart with JSON and JavaScript June 6th, 2008 by Alex Batsuev

Until now AnyChart was able to get data only in XML format. However it’s not always convenient and requires at least knowledge of XML.

Now we make the life of AnyChart users easier and add the ability of handy Flash chart implementation in JavaScript. Now AnyChart.js has a new method – setJSData, that allows you to set parameters and data to the chart as a JavaScript object.

You can view a simple example here:

How to create an object with settings and data:An object with settings and data has the same structure as AnyChart XML. XML nodes and attributes are properties. Nodes, that can be repeated (for example, <point />) are arrays.

For example:

var chartData = {
charts: {
chart: {
chart_settings: {
title: { text: "Chart Title" } },
data: {
series: [
point: [{name: "pt1", y: 12}, {name: "pt2", y: 23}]


var chartData = {}
chartData.charts = {};
chartData.charts.chart = {};
chartData.charts.chart.chart_settings = {};
chartData.charts.chart.chart_settings.title = {};
chartData.charts.chart.chart_settings.title.text = "Chart Title"; = {}; = [];

var seriesObj = {};
seriesObj.point = [];
seriesObj.point.push({name: "Pt1", y: 12});
seriesObj.point.push({name: "Pt1", y: 23});;

Object’s structure is equivalent to XML structure. The description of XML you can find here:

Setting chart description object to AnyChart is done using setJSData method.

Also we’ve created several examples of using setJSData, including JSON example:

1. An example of object-creation using JavaScript:

2. An example of JSON-creation forming:

3. An example of JSON-data loading from the text file using AJAX: