FusionCharts API-Methods: clearChart

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 clearChart() method -->
<div id="indicatorDiv">Method Name: <strong>clearChart()</strong>
    <p>Clears the entire chart canvas when a real-time chart is being updated. Click <a href="http://www.fusioncharts.com/dev/api/fusioncharts/fusioncharts-methods.html#clearChart" target="blank">here</a> to read more about this method.</p>
    <p>Click <strong>Clear Chart</strong> to clear the chart canvas.</p>


<div class="text-center">
	<button id="clear_chart" class="mb-20">Clear Chart</button>
	
	<div id="chart-container">FusionCharts will render here</div>
</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;
}
#clear_chart {
    height: 25px;
    font-size: 13px;
}

JavaScript

FusionCharts.ready(function () {
    var stockPriceChart = new FusionCharts({
        id: "stockRealTimeChart",
        type: 'realtimeline',
        renderAt: 'chart-container',
        width: '400',
        height: '250',
        dataFormat: 'json',
        dataSource: {
            "chart": {
                "caption": "Real-time stock price monitor",
                    "subCaption": "Harry's SuperMart",
                    "xAxisName": "Time",
                    "yAxisName": "Stock Price",
                    "numberPrefix": "$",
                    "refreshinterval": "5",
                    "yaxisminvalue": "35",
                    "yaxismaxvalue": "36",
                    "numdisplaysets": "10",
                    "labeldisplay": "rotate",
                    "showValues": "0",
                    "showRealTimeValue": "0",
                    "theme": "fint",
                    "captionFontSize": "13",
                    "subCaptionFontSize": "12"
            },
                "categories": [{
                "category": [{
                    "label": "Day Start"
                }]
            }],
                "dataset": [{
                "data": [{
                    "value": "35.27"
                }]
            }]
        },
            "events": {
            "initialized": function (e) {
                function addLeadingZero(num) {
                    return (num <= 9) ? ("0" + num) : num;
                }

                function updateData() {
                    // Get reference to the chart using its ID
                    var chartRef = FusionCharts("stockRealTimeChart"),
                        // We need to create a querystring format incremental update, containing
                        // label in hh:mm:ss format
                        // and a value (random).
                        currDate = new Date(),
                        label = addLeadingZero(currDate.getHours()) + ":" + addLeadingZero(currDate.getMinutes()) +...