FusionCharts API-Event: dataLoadRequestCancelled

Created using FusionCharts Suite XT - www.fusioncharts.com

by Nikita Jhanglani

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 event parameters, and their values, when dataLoadRequestCancelled event is triggered-->
<div id="indicatorDiv">Event name: <b> dataLoadRequestCancelled </b> 
    <br>
    <br>Triggered when the default behavior of the dataLoadRequested event is cancelled by calling the eventObj.preventDefault() method.</br>
    <br>All events, when triggered, will provide two parameters for the handler - eventObj (object containing information generic to all events) and dataObj (object containing information specific to an event)</br>
        <br>Scroll down to the table rendered below the chart to view information contained in the dataObj object. To view information contained in the eventObj object, open the console.</br>
    </br>
</div>
<div id="chart-container">FusionCharts will render here</div>
<div>
    <div>
        <div id="header">
            <div class="parameter-name">Parameter Name</div>
            <div class="parameter-value">Parameter Value</div>
        </div>
        <div id="attrs-table"></div>
    </div>
</div>

CSS

#header {
    display: none;
}
#indicatorDiv {
    width: 500px;
    font-family:'Arial', 'Helvetica';
    font-size: 14px;
}
p {
    margin-top: 20px;
    margin-bottom: 20px;
}
#attrs-table {
    text-align: center;
    width: 500px;
}
.parameter-name, .parameter-value {
    width: 250px;
    font-weight: bold;
    text-align: center;
    float: left;
}
.title, .value {
    float:left;
    width: 230px;
    height: 20px;
    background: #fff;
    padding: 5px 10px;
}
.title {
    clear: left;
}
.title:nth-child(4n+1), .value:nth-child(4n+2) {
    background: rgb(0, 117, 194);
    color: #fff;
}
.value {
    word-wrap: break-word;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

JavaScript

FusionCharts.ready(function () {
    var ageGroupChart = new FusionCharts({
        type: 'pie2d',
        renderAt: 'chart-container',
        width: '450',
        height: '250',
        dataFormat: 'jsonurl',
        dataSource: 'http://static.fusioncharts.com/fiddle/getSampleJSON.php',
            "events": {
                dataLoadRequested: function(eventObj, dataObj) {
                    // Cancel the dataLoad. This will trigger the dataLoadRequestCancelled event.
                    eventObj.preventDefault();
                },
            /**
             * @description
             * Triggered when the default behavior of the dataLoadRequested event is cancelled by calling the eventObj.preventDefault() method.
             *
             * @param {Object} eventObj: An object containing all the details related to this event like eventId, sender (the chart object itself), etc.
             * @param {Object} dataObj: An object containing all the details related to the data being loaded like data format, url, etc.
             */
                dataLoadRequestCancelled: function (eventObj, dataObj) {
                console.log(eventObj);
                var header = document.getElementById('header');
                header.style.display = 'block';

                var tempDiv = document.createElement('div');
                var attrsTable = document.getElementById('attrs-table');
                var titleDiv, valueDiv;
                // Iterating through all the properties in argObj and adding it to the DOM
                for (var prop in dataObj) {
                    titleDiv = document.createElement('div');
                    titleDiv.className = 'title';
                    titleDiv.innerHTML = prop;

                    valueDiv = document.createElement('div');
                    valueDiv.className = 'value';
                    valueDiv.innerHTML = dataObj[prop];

                    tempDiv.appendChild(titleDiv);
                   ...