You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your https://ej2.syncfusion.com/react/demos/#/bootstrap5/chart/update-spline demo is awesome. For a real-world scenario, what JavaScript-client compatible streaming sources could be used to load splineData? Websocket, MQTT, AMQP, GCPubSub, ...? It would be great to see an example using a public data source.
The text was updated successfully, but these errors were encountered:
mrbluecoat
changed the title
Supported data sources for update-spline real-time steaming chart
Supported data sources for update-spline real-time streaming chart
Aug 6, 2024
Thank you for your query regarding supported data sources for real-time streaming charts. The link you referenced is indeed for EJ1. To assist you, we have created a React sample that demonstrates how to fetch data from a WebSocket and utilize the addPoint and removePoint methods.
Below is a brief overview of the implementation:
Code Snippet :
useEffect(()=>{constsocket=newWebSocket('ws://localhost:8080');// Your WebSocket serversocket.onmessage=(event)=>{constparsedData: ChartData=JSON.parse(event.data);addData(parsedData);// Call addData to add new data};socket.onclose=()=>{console.log('WebSocket connection closed');};// Clean up the socket connection on component unmountreturn()=>{socket.close();};},[]);// Function to add new data to the chartconstaddData=(newData: ChartData)=>{// Add data to the chart using addPoint method with null checksif(chartRef.current?.series[0]){(chartRef.current.series[0]asSeries).addPoint({x: newData.x,y: newData.y},800);// Update the chart with new data}};// Function to remove the data from the chart using removePointconstremoveData=()=>{if(chartRef.current?.series[0]&&Object.keys((chartRef.current.series[0]asSeries).dataSource).length>2){// Remove the first point (oldest data point) safely(chartRef.current.series[0]asSeries).removePoint(0,800);// Update the chart by removing the oldest point}};// Call removeData every few seconds to limit the number of points displayeduseEffect(()=>{constinterval=setInterval(()=>{removeData();},5000);// Adjust the time as needed (e.g., every 5 seconds)return()=>clearInterval(interval);},[]);
Your https://ej2.syncfusion.com/react/demos/#/bootstrap5/chart/update-spline demo is awesome. For a real-world scenario, what JavaScript-client compatible streaming sources could be used to load
splineData
? Websocket, MQTT, AMQP, GCPubSub, ...? It would be great to see an example using a public data source.The text was updated successfully, but these errors were encountered: