Loading
Real-time Gauges
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 |
---|---|---|
|
|
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. |
|
|
This method returns the data currently being shown by the gauge. |
|
|
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 |
---|---|
|
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 the data stream URL, like ? or &, you will have to URL Encode the entire |
|
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. |
|
This attribute is used to set a constantly changing data stamp that can be added to the real-time data URL, so as to maintain a state. |
The data structure needed to enable real-time updates from the server is given below:
{
"chart": {
"theme": "fint",
"caption": "Diesel Level in Generator",
"subcaption": "Bakersfield Central",
"lowerLimit": "0",
"upperLimit": "120",
"lowerLimitDisplay": "Empty",
"upperLimitDisplay": "Full",
"numberSuffix": " ltrs",
"showValue": "1",
"chartBottomMargin": "45",
"dataStreamUrl": "../../../resources/php/gauge-and-widgets-guide-cylinder-gauge-real-time-gauges-php-1.php",
"refreshInterval": "2",
"refreshInstantly": "1"
},
"value": "110"
}
Stopping and Restarting Real-time Updates
You can stop the chart from polling the server for any more real-time updates. To do this, you use the stopUpdate
command as shown below:
To restart updates from the server, use the startUpdate
command from the server as shown below:
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 |
---|---|---|
|
None |
This method stops the chart from self-updating. |
|
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:
{
"chart": {
"theme": "fint",
"caption": "Diesel Level in Generator",
"subcaption": "Bakersfield Central",
"lowerLimit": "0",
"upperLimit": "120",
"dataStreamUrl": "../../../resources/php/gauge-and-widgets-guide-cylinder-gauge-real-time-gauges-php-2.php",
"lowerLimitDisplay": "Empty",
"upperLimitDisplay": "Full",
"numberSuffix": " ltrs",
"showValue": "1",
"chartBottomMargin": "45",
"refreshInterval": "2"
},
"value": "110"
}
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:
Event Name | Description |
---|---|
|
This event is raised every time the real-time gauge updates itself with new data. This event is raised in any of the following cases: |
The data structure needed to configure the gauge to listen to this event is given below:
{
"chart": {
"theme": "fint",
"caption": "Diesel Level in Generator",
"subcaption": "Bakersfield Central",
"lowerLimit": "0",
"upperLimit": "120",
"lowerLimitDisplay": "Empty",
"upperLimitDisplay": "Full",
"numberSuffix": " ltrs",
"showValue": "0",
"chartBottomMargin": "60"
},
"value": "110",
"annotations": {
"origw": "400",
"origh": "190",
"autoscale": "1",
"groups": [
{
"id": "range",
"items": [
{
"id": "rangeBg",
"type": "rectangle",
"x": "$canvasCenterX-125",
"y": "$chartEndY-50",
"tox": "$canvasCenterX +145",
"toy": "$chartEndY-95",
"fillcolor": "#6caa03"
},
{
"id": "rangeText",
"type": "Text",
"fontSize": "11",
"fillcolor": "#333333",
"text": "Available Volume : 110 ltrs",
"x": "$chartCenterX-35",
"y": "$chartEndY-70"
}
]
}
]
}
}
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:
Event Name | Description |
---|---|
|
This event is raised when an error occurs while performing real-time update using |
The data structure needed to configure the gauge to listen to this event is given below:
{
"chart": {
"theme": "fint",
"caption": "Diesel Level in Generator",
"subcaption": "Bakersfield Central",
"lowerLimit": "0",
"upperLimit": "120",
"lowerLimitDisplay": "Empty",
"upperLimitDisplay": "Full",
"numberSuffix": " ltrs",
"showValue": "0",
"chartBottomMargin": "60",
"dataStreamURL": "dummyErrorURL/cylinderData.php"
},
"value": "110"
}
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 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. -
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.