FusionCharts API-Methods: transcodeData static

Created using FusionCharts Suite XT - www.fusioncharts.com

by FusionCharts

HTML

<script src="https://static.fusioncharts.com/code/latest/fusioncharts.js"></script>
<script src="https://static.fusioncharts.com/code/latest/fusioncharts.charts.js"></script>
<script src="https://static.fusioncharts.com/code/latest/themes/fusioncharts.theme.fint.js"></script>
<!-- This sample shows the usage of the transcodeData() method -->
<div id="indicatorDiv">Method Name: <b>transcodeData()</b>   
   <p>Transcodes data from one supported format to another, without initializing a new instance of FusionCharts. Click <a href="http://www.fusioncharts.com/dev/api/fusioncharts/fusioncharts-methods.html#static-transcodeData" target="_blank">here</a> to read more about the <b>transcodeData</b> method.</p>
   <p>Click <b>Convert Data</b> to convert the chart from the JSON format into the CSV format.</p>
   
    <div class="text-center mb-20">
    	<button id="transcode_data">Transcode data</button>
    </div>
    	<div id="msg"></div>
    	   
    	<div id="chart-container" class="container">FusionCharts will render here.</div>
</div>

CSS

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

strong{
  font-weight: bold;
}

.text-center {
  text-align: center;
}

p {
  margin: 10px auto;
}

.mb-20 {
  margin-bottom: 20px;
}
#indicatorDiv {
    width: 500px;
    font-family:'Arial', 'Helvetica';
    font-size: 13px;
}
#msg {
    overflow:auto;
}
#transcode_data {
    font-size: 13px;
}
#msg {
    overflow:auto;
    font-family:'Arial', 'Helvetica';
    font-size: 13px;
}

JavaScript

FusionCharts.ready(function () {
    var data = {
        "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"
        }]
    };

    var revenueChart = new FusionCharts({
        type: 'doughnut2d',
        renderAt: 'chart-container',
        width: '350',
        height: '350',
        dataFormat: 'json',
        dataSource: data
    }).render();

    /**
     * @description
     * FusionCharts supports a number of formats in which data can be provided. The static transcodeData() method transcodes data from one supported format to another, without initializing a new instance of FusionCharts. It is very useful when you already have a set of data stored or prepared in one FusionCharts data format and want to convert it to another format. The fact that we do not need to instantiate a new FusionCharts instance speeds the conversion process.
     *
     * @param {Object} data: Data to transcode
     * @param {FusionCharts-dataFormat} source: Source format
     * @param {FusionCharts-dataFormat} target: Target format
     * @param {Boolean} advanced: Request the transcoding to return data in a verbose format where it returns the conversion result along with additional trancosing information. default: false.
     * usage: FusionCharts.transcodeData();
     *         
     */
    function getTranscodedData() {

        var csv = FusionCharts.transcodeData(data, "json", "csv");
   ...