FusionCharts API-Methods: setJSONData

Created using FusionCharts Suite XT - www.fusioncharts.com

by sunil puvvada

HTML

<script src="http://static.fusioncharts.com/code/latest/fusioncharts.js"></script>
<script src="http://static.fusioncharts.com/code/latest/fusioncharts.charts.js"></script>
<script src="http://static.fusioncharts.com/code/latest/themes/fusioncharts.theme.fint.js"></script>
<!-- This sample shows the usage of the setJSONData() method. -->
<div id="indicatorDiv">
    <center>
      <label id="label">Select a year:
        <select id="set_json_data">
          <option value="lastyear">2014</option>
          <option value="thisyear">2015</option>
        </select>
      </label>
     
    <div id="chart-container">FusionCharts will render here</div>

CSS

body {
  padding: 5px;
  margin: 0 auto;
}

#indicatorDiv {
  width: 500px;
  font-family: 'Arial', 'Helvetica';
  font-size: 13px;
}

#label {
  font-family: 'Arial', 'Helvetica';
  font-size: 13px;
}

#theme-type {
  height: 25px;
  font-size: 13px;
}

JavaScript

FusionCharts.ready(function() {
  var yearlyData = {
    "lastyear": {
      "chart": {
        "caption": "Split of Revenue by Product Categories",
        "subCaption": "Last year",
        "numberPrefix": "$",
        "theme": "fint",
        "captionFontSize": "13",
        "subcaptionFontSize": "12",
        "subcaptionFontBold": "0"
      },
      "data": [{
        "label": "Food",
        "value": "28504"
      }, {
        "label": "Apparels",
        "value": "14633"
      }, {
        "label": "Electronics",
        "value": "10507"
      }, {
        "label": "Household",
        "value": "4910"
      }]
    },
    "thisyear": {
      "chart": {
        "caption": "Split of Revenue by Product Categories",
        "subCaption": "This year",
        "numberPrefix": "$",
        "theme": "fint",
        "captionFontSize": "13",
        "subcaptionFontSize": "12",
        "subcaptionFontBold": "0"
      },
      "data": [{
        "label": "Food",
        "value": "5000"
      }, {
        "label": "Apparels",
        "value": "14633"
      }, {
        "label": "Electronics",
        "value": "1000"
      }, {
        "label": "Household",
        "value": "20000"
      }]
    }
  };
  var revenueChart = new FusionCharts({
    type: 'doughnut2d',
    renderAt: 'chart-container',
    width: '300',
    height: '300',
    dataFormat: 'json',
    dataSource: yearlyData.lastyear
  }).render();

  /**
             * @description
             * The setJSONData() method sets chart data in the JSON data format. When this function is called on a chart that has already rendered, it immediately updates the chart with the new data. The function can also be used to set data for a new chart.
.
             *@param {Object} data: JSON data to be set for the chart, as a string or as a JavaScript object
            
 
             * usage: chartObject.setJSONData(data); 
          
             */
  var year = document.getElementById("set_json_data");

  function change()...