Forum Replies Created by connect.javed001

Viewing 1 post (of 1 total)
  • in reply to: How can I use PHP MySQL Dynamic data #20422

    Hello sir, I am storing sensor data in mysql database ,now I want to use canvasJS to show realtime data from mysql database on web page.
    Jquery code for updating chart data

    function fData(){
        var lastid= $('#lastId').val(); 
       $.ajax({
                            url: httppath+"pages/fetchData",
                            type: "post",
                            data:{pId:$('#pid').val(),'lastId':lastid},
                            dataType:"json",
                            success: function (res) {
                                 if(res['Pt']!=='' || res['Pt']!=" "){
                                   $('#lastId').val(res["Pt"]['id']);
                                     updateChart(res['Pt']);
                                 }
                            },
                            error: function(jqXHR, textStatus, errorThrown) {
    //                           console.log(textStatus, errorThrown);
                            }
                        });
    }   
       var dps = []; // dataPoints
       var xVal;
       var yVal;	
       var chart = new CanvasJS.Chart("chartContainer",{
          	title :{
          		text: "Live Data"
          	},
          	axisX: {						
          		title: "Axis X Title"
          	},
          	axisY: {						
          		title: "Pulse Rate"
          	},
          	data: [{
          		type: "line",
          		dataPoints : dps
          	}]
          });
    
          chart.render();
          
          var updateChart = function (data) {
          	yVal = data['sensor_value'];
          	dps.push({x: xVal,y: yVal});
          	console.log(dps);
            xVal++;
            if (dps.length >  10 )
          	{
          		dps.shift();				
          	}
          	chart.render();		
    	// update chart after specified time. 
          };
Viewing 1 post (of 1 total)