| JavaScript API | ||||||||||||||||||||||||||||||||||||||||||||||||
The Bulb gauge exposes the following JavaScript APIs: |
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
Additionally, you can control the annotations using JavaScript API, which has been discussed in the annotations sections. |
||||||||||||||||||||||||||||||||||||||||||||||||
| Using these methods | ||||||||||||||||||||||||||||||||||||||||||||||||
To use any of these methods, you need to refer to the chart and then call any of these methods. To refer to a chart, you can use the DOMID of the chart and pass it using any of the following ways: var chartRef = FusionCharts("myChartId");
or var chartRef = FusionCharts.items["myChartId"]; The legacy function getChartFromId() still works as show below: var chartRef = getChartFromId("myChartId");
However, note that getChartFromId() has been deprecated. You can call the JavaScript APIs of a chart only after it has rendered. You can use the FC_Rendered event tracker or the Rendered event listener to check if a chart has rendered. For more information, please see FusionWidgets XT and JavaScript section. The example below shows how to call getData() when a Bulb gauge is updated with data in real-time: |
||||||||||||||||||||||||||||||||||||||||||||||||
<html>
<head>
<title>FusionWidgets XT - JS API</title>
<script type="text/javascript" src="../Charts/FusionCharts.js"></script>
<script language="javascript">
//FC_ChartUpdated method is called when chart has changed value in real-time.
function FC_ChartUpdated(DOMId){
//Check if DOMId is that of the chart we want
if (DOMId=="ChId1"){
//Get reference to the chart
var chartRef = FusionCharts(DOMId);
//Get the changed value
var chartValue = chartRef.getData();
//.... Do what your application demands...
}
}
</script>
</head>
<body>
<div id="chart1div">This text is replaced by a bulb gauge</div>
<script type="text/javascript">
var chart1 = new FusionCharts("../Charts/Bulb.swf", "ChId1", "100", "100", "0", "1");
chart1.setXMLUrl("Data.xml");
chart1.render("chart1div");
</script>
</body>
</html> |
||||||||||||||||||||||||||||||||||||||||||||||||
|
FusionWidgets XT (v3.2) introduces two new events to track real-time updates on charts and gauges. The names of the two events are: RealtimeUpdateComplete and RealtimeUpdateError. RealtimeUpdateComplete event is raised when a real-time gauge or chart completes updating data. Example implementation:
FusionCharts("myChartId").addEventListener ("RealtimeUpdateComplete" ,
function(event, parameter)
{
alert( "Updated value : " + event.sender.getData() );
}
);
Existing JavaScript implementations using FC_ChartUpdated event will continue to function without any problem. RealtimeUpdateError event is raised when an error occurs while updating data in a real-time gauge or chart. This event passes the HTTP Status (as number) of the error occurred. Example implementation:
FusionCharts("myChartId").addEventListener ("RealtimeUpdateError" ,
function(event, parameter)
{
alert( "Problem occurred while updating real-time data. The error status code is" + parameter.httpStatus );
}
);
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Troubleshooting | ||||||||||||||||||||||||||||||||||||||||||||||||
|
While accessing any of the JavaScript methods listed above, if you get an error like "... is not a function of ...", make sure of the following points:
|
||||||||||||||||||||||||||||||||||||||||||||||||