You are viewing documentation for an older version. For current documentation - click here.

PowerCharts XT can also build charts using JSON (JavaScript Object Notation) data format. JSON is a light-weight and simple data format that is easy to read and understand. Though derived from JavaScript, the data structure is language-independent, with encoders and parsers available for virtually every programming language.

Important: To use JSON data format with PowerCharts XT, you will need to embed the charts using FusionCharts JavaScript Class (FusionCharts.js), as the charts internally still use XML. The JavaScript class provides the bridge between JSON and XML.

Here are a few basic things to know about JSON data:

  • JSON data is text based data consisting of key and value pairs in format key : value . The values have data associated with them
  • You can make up your own key-value pairs like name : "John Doe" to store data
  • Every JSON data is enveloped by curly brace and key:value pairs are comma separated, like { firstName : "John" , lastName: "Doe" }. In JavaScript, this format is called an Object
  • A key can be a value within single or double-quotes e.g. { "name" : "John Doe" }
  • You can use Objects as values too. For example, { "employee" : { "name" : "John Doe" , "department" : "Project Manager" , "age" : 35 } }
  • In JSON, the basic data types are:
    • Number (integer or real)
    • String (double-quoted Unicode with backslash escaping)
    • Boolean (1 or 0 in FusionCharts JSON)
    • null
    • Array (an ordered sequence of values of Number, String, Boolean, null, Object or Array type, comma-separated and enclosed in square brackets). For example, [ "employees" : [ "Employees" , { "name" : "John Doe" } , 35 ]
    • Object (a collection of key:value pairs, comma-separated and enclosed in curly braces. Value can be of Number, String, Boolean, null, Object or Array type). For example, { "employee" : { "name" : "John Doe" , "department" : "Project Manager" , "age" : 35 } }

A PowerCharts XT chart is controlled by a single JSON data source, that is, the same source contains data to plot, functional settings and cosmetic properties. There are many properties that you can define for each chart type. However, it is not necessary to define all the properties for a given chart. For example, if you do not want to change the default setting of the canvas (color, alpha, etc.), you don't have to define any property for the canvas - the default values will be assumed. Thus, each chart can be generated using minimal properties.

PowerCharts XT has a specific JSON format for each chart. The JSON structure for PowerCharts XT closely follows the XML format for PowerCharts XT. All the XML nodes are represented as JSON Objects, where as all the attributes are set as properties. Here is a sample XML Vs JSON that would help you understand it quickly.

XML JSON

<chart xAxisName='Month' yAxisName='Revenue' showValues='0'>
 
    <categories>
       <category  label='Jan' />
       <category label='Feb' showValue='1'/> 
       <category label='Mar' />
    </categories>
 
    <dataset seriesName='2006'>
       <set value='27400' />
       <set value='29800' />
       <set value='25800' />
    </dataset>

    <dataset seriesName='2005'>
       <set value='10000' />
       <set value='11500' />
       <set value='12500' />
    </dataset>

    <trendlines>
       <line startValue='26000' color='91C728' />
    </trendlines>

<styles>
       <definition>
             <style name='CanvasAnim' type='animation' param='_xScale' start='0' duration='1' />
       </definition>
 
       <application>
             <apply toObject='Canvas' styles='CanvasAnim' />
       </application>   
    </styles>

</chart>
{
  "chart":{ "xaxisname":"Month", "yaxisname":"Revenue",  "showvalues":"0"  },

  "categories":[{
      "category":[
         {"label":"Jan"},
         {"label":"Feb", "showvalue":"1" },
         {"label":"Mar"} 
      ]
    }
  ],

 "dataset":[{
      "seriesname":"2006",
      "data":[
        {  "value":"27400"     },
        {  "value":"29800"     },
        {  "value":"25800"     }
      ]
    },
    {
      "seriesname":"2005",
      "data":[
        {  "value":"10000"   },
        {  "value":"11500"   },
        {  "value":"12500"   }
      ]
    }
  ],
  "trendlines":[{
      "line":[{ "startvalue":"26000", "color":"91C728"  }  ]
    }
  ],
  "styles":{
    "definition":[{
        "name":"CanvasAnim",
        "type":"animation",
        "param":"_xScale",
        "start":"0",
        "duration":"1"
      }
    ],
    "application":[{  "toobject":"Canvas", "styles":"CanvasAnim"   }  ]
  }
}    

The above comparison shows that the JSON data contains:

  • A "chart" Object which is equivalent to the <chart> XML Node
  • All the <chart> node XML attributes are provided as properties (like "xaxisname":"Month", "yaxisname":"Revenue")of the "chart" object in the JSON
  • "categories" Object is equivalent to the <categories> node of the XML
  • An array named "category" contains a list of Objects each of which is equivalent to a <category> node
  • The properties defined in each Object of the "category" Array maps the attributes defined in respective <category> node
  • Similarly "dataset" is an Array which contains a list of Objects, each representing a <dataset> XML node
  • The collection of all <set> nodes of a dataset reside as "data" Array in the JSON
  • Similarly trendline, styles, application, definition objects and line, style, apply Arrays are defined

Since, the JSON format has close resemblance with the XML format, we will mostly use the term XML attribute (for JSON properties) and XML element/node (for JSON Object or Array) in the whole documentation. Likewise, the XML API page of each chart will be the source for JSON Object and properties. Moreover, you can always use the FusionCharts Data Format Conversion Tool to convert your XML to JSON and vice-versa