The gauges in the FusionCharts Suite XT are real-time gauges that can continuously request and render new data without involving a page refresh. The gauges achieve this functionality in two ways:
Using JavaScript API
Using server-side scripts
In this section, you will be shown how you can:
Configure real-time updates using JavaScript API
Configure real-time updates using server-side script
Configure real-time events
Troubleshoot real-time gauges
Configuring Real-time Updates using JavaScript API
Real-time Data Format
The real-time data format for gauges depends on the data value to be passed.
In the simplest form, if you're looking to update the cylinder gauge, you need to pass a single value to the value
attribute using the JSON key-value pair format. If this data is within the acceptable range of the chart, the chart will be updated to depict this value.
However, to dynamically pass values to the gauge, you use the JavaScript API.
A cylinder gauge configured to receive real-time updates using the JavaScript API looks like this:
The cylinder gauge exposes the following JavaScript APIs:
Function Name | Parameter | Description |
---|---|---|
feedData(strData) |
strData |
This method feeds real-time data to the chart using the JavaScript API. The data has to be in the same format as provided by real-time data provider page. |
getData() |
None |
This method returns the data currently being shown by the gauge. |
setData(value)
|
value |
This method sets the data for the chart. The value should be within the limits of the gauge. |
The data structure needed to configure real-time data updates using JavaScript API is given below:
Configuring Real-time Updates using Server-side Script
Another way to update a chart in real-time is by using server-side script.
A cylinder gauge configured to receive real-time updates using the server-side script looks like this:
The new attributes that need to be added for receiving real-time updates from the server are:
Attribute Name | Description |
---|---|
dataStreamURL |
This attribute is used to set the path of the page which is supposed to relay real-time data to the chart. If you have special characters as a part of your data stream URL, like ? or &, you will have to URL Encode the entire dataStreamURL .This page needs to be on the same sub-domain on which the chart is hosted and invoked from. Otherwise, security measures will restrict it from accessing the data and hence the real-time feature won't work. Example: dataStreamURL='liveQuote.aspx?name=xyz' |
refreshInterval |
This attribute is used to specify the number of seconds after which the chart will look for new data. This process will happen continuously - i.e., if you specify 5 seconds here, the chart will look for new data every 5 seconds. |
dataStamp |
This attribute is used to set a constantly changing data stamp that can be added to real time Data URL, so as to maintain a state. Please see the section Real time capabilities > Adding data stamp |
The data structure needed to enable real-time updates from the server is given below:
Stopping and Restarting Real-time Updates from the Server
You can stop the chart from polling the server for any more real-time updates. To do this, you use the stopUpdate
command from the server as shown below:
"stopUpdate": “1”;
To restart updates from the server, use the startUpdate
command from the server as shown below:
"startUpdate": “1”;
A cylinder gauge configured to allow stopping and restarting real-time updates from the server, looks like this:
The cylinder gauge exposes the following JavaScript APIs for stop update and restart update:
Function Name | Parameter | Description |
---|---|---|
stopUpdate() |
None | This method stops the chart from self-updating. |
restartUpdate() |
None | If you've stopped the update of the chart, you can resume the update using this method. |
The data structure needed to stop receiving real-time updates from the server is given below:
Configuring Real-time Events
You can use the realTimeUpdateCompete
and the realTimeUpdateError
events to track real-time updates on charts and gauges.
The realTimeUpdateComplete Event
This event is raised when a real-time gauge or chart completes updating data.
A cylinder gauge configured to listen to the realTimeUpdateComplete
event looks like this:
Given below is a brief description of the realTimeUpdateComplete
event:
Attribute Name | Description |
---|---|
realtimeUpdateComplete |
This event is raised every the real-time gauge updates itself with new data. This event is raised in any of the following cases: Real-time update using datastreamURL Real-time update using JavaScript API (using setData , feedData , setDataForId functions)Real-time update of the gauge through user interaction (through edit mode) The event arguments provided in the advanced model are: eventObject : This object contains the eventId , eventType , and sender properties.argumentsObject : This object contains the values of the updated data and the previous data. |
The data structure needed to configure the gauge to listen to this event is given below:
The realTimeUpdateError Event
This 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 as shown below:
A cylinder gauge configured to listen to the realTimeUpdateError
event looks like this:
Given below is a brief description of the realtimeUpdateError
event:
Attribute Name | Description |
---|---|
realtimeUpdateError |
This event is raised when an error occurs while performing real-time update using datastreamURL .
The event arguments provided in the advanced model are:eventObject : This object contains eventId , eventType and sender properties.argumentsObject : This object contains the property listed below:httpStatus : It contains the HTTP Error status value as number (e.g., 404) |
The data structure needed to configure the gauge to listen to this event is given below:
Troubleshooting Real-time Gauges
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:
Make sure that you are not calling the JavaScript method before the chart has loaded and rendered. You need to use the
FC_Rendered
function or define an event listener for theRendered
event of the chart to track the loading of chart.Make sure that you are NOT running the chart from local file system (C:\ , D:). Instead, run the chart from behind a server (localhost - IIS, Apache etc.). This is because, by default, security settings do not allow the chart to perform JavaScript interactions on the local file system.
There! You have now seen how you can configure real-time updates and events for a cylinder gauge.