Introduction #
SmartChart supports WebSocket as a data source for real-time data push scenarios. Unlike HTTP polling, WebSocket provides server-push based real-time updates, ideal for live dashboards and monitoring screens.
Use Cases #
- Real-time stock market data display
- IoT device status monitoring
- Live sports/event data updates
- Real-time production line metrics
Usage #
Uses custom data source functions. Create a WebSocket connection that receives pushed data and returns it for visualization.
import websocket
import json
def dataset(*args, **kwargs):
"""
Returns query dataset from WebSocket
:return: 2D array or JSON dict
"""
sqlList = args[0]
config = args[1]
ws = websocket.WebSocket()
ws.connect(config['host'])
# Send query if needed
if sqlList:
ws.send(sqlList[0])
# Receive data
result = ws.recv()
ws.close()
return json.loads(result)
For continuous real-time updates, use the chart’s JavaScript to establish a WebSocket connection and update the chart dynamically.