<!DOCTYPE html><html lang="en"><head><!-- Ignite UI Required Combined CSS Files --><link href="http://cdn-na.infragistics.com/igniteui/2015.1/latest/css/themes/infragistics/infragistics.theme.css" rel="stylesheet" /><link href="http://cdn-na.infragistics.com/igniteui/2015.1/latest/css/structure/infragistics.css" rel="stylesheet" /><!--CSS file specific for chart styling --><link href="http://cdn-na.infragistics.com/igniteui/2015.1/latest/css/structure/modules/infragistics.ui.chart.css" rel="stylesheet" /></head><body> <div style="width: 80%; min-width: 210px;"> <div id="chart"></div> </div> <script src="http://modernizr.com/downloads/modernizr-latest.js"></script> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script> <script src="../js/mqttws31-min.js"></script> <script src="http://cdn-na.infragistics.com/igniteui/2015.1/latest/js/infragistics.core.js"></script> <script src="http://cdn-na.infragistics.com/igniteui/2015.1/latest/js/infragistics.dv.js"></script> <script> $(document).ready(function(){ /* making request for live speed update*/ $.ajax({ type: "GET", url: "http://10.9.177.82:8080/TrainAnalyticsAPI/api/speed/train/updates/1", headers: { 'Access-Control-Allow-Origin': '*' }, cache:false, crossDomain: true, dataType: 'json', contentType: "application/json; charset=UTF-8", success: function(response){ alert("got response"); console.log(response); topicName(response); }, error: function(textStatus, errorThrown){ alert("error"); console.log(textStatus); console.log(errorThrown); }, complete: function () { } }); });var speedTopic;var data=[];function topicName(response){ var saObj = response.topic; console.log("topic is ---> "+saObj); speedTopic = (saObj).toString(); console.log("speedTopic---->"+speedTopic); connect();}function connect(){ // Create a client instance client = new Paho.MQTT.Client("10.9.65.121", 8000, "50"); client.onConnectionLost = onConnectionLost; client.onMessageArrived = onMessageArrived; // connect the client client.connect({onSuccess:onConnect}); // called when the client connects function onConnect() { alert("connected"); // Once a connection has been made, make a subscription and send a message. console.log("onConnect"); client.subscribe(speedTopic); } // called when the client loses its connection function onConnectionLost(responseObject) { if (responseObject.errorCode !== 0) { console.log("onConnectionLost:"+responseObject.errorMessage); } } // called when a message arrives function onMessageArrived(message) { console.log("onMessageArrived:"+message.payloadString); var obj = jQuery.parseJSON(message.payloadString); data.push(obj); drawSpeed(); } }function drawSpeed() { console.log("Data inside draw---->"+JSON.stringify(data)); $("#chart").igDataChart({ width : "100%", height : "400px", title : "Time vs Brake Cylinder", horizontalZoomable : true, verticalZoomable : true, windowResponse : "immediate", overviewPlusDetailPaneVisibility : "visible", dataSource : data, axes : [ { name : "NameAxis", type : "categoryX", title : "Time", label : "entered" }, { name : "SpeedAxis", type : "numericY", minimumValue : 0, title : "KMPH" } ], series: [{ title : "SpeedLimit", name : "SpeedLimit", type : "spline", xAxis : "NameAxis", yAxis : "SpeedAxis", isTransitionInEnabled : true, isHighlightingEnabled : true, showTooltip : true, thickness: 3, valueMemberPath : "speedLimit"},{ title : "Speed", name : "Speed", type : "spline", xAxis : "NameAxis", yAxis : "SpeedAxis", isTransitionInEnabled : true, isHighlightingEnabled : true, showTooltip : true, thickness: 3, valueMemberPath : "value"} ] });} </script></body></html>
The above code id for receiving the data from mqtt broker, and plotting the graph for the received data, It should be something like live data plotting,
onMessageArrived call back method is callling the draw(), even X and Y axes are coming with the specied values and label, only thing is data is not plotting on the graphPlease correct me where Iam wrong
Hello Suma,
Thank you for contacting Infragistics!
In order to create a "live" chart you can use the addItem method (http://www.igniteui.com/help/api/2015.1/ui.igdatachart#methods:addItem) and insert new values when you have new data.
You can also refer to our motion framework sample => https://www.igniteui.com/data-chart/motion-framework?_ga=2.151724793.1361514943.1564061678-1320467891.1559052143
Let me know if you need further assistance.