Forum Replies Created by chanakeat

Viewing 1 post (of 1 total)
  • in reply to: Multiple charts from one JSON result #21842

    Hi there!
    How can I render 2 line chart every second with my code.

    <script type="text/javascript">
    		window.onload = function () {
    			var dps1 = [];
    			var dps2 = [];
    			var chart = new CanvasJS.Chart("chartContainer", {
    				toolTip:{
    			   	shared: true,
    			 	},
    				data: [
    					{
    						type: "line",
    						dataPoints: dps1
    					},
    					{
    						type: "area",
    						dataPoints: dps2
    					}
    				]
    			});
    			$.getJSON("data_1.php", function (data) {
    
    				for( var i = 0; i < data.length; i++) {
    					dps1.push({ label: data[i].label, y: data[i].y });
    					dps2.push({ label: data[i].label, y: data[i].y2 });
    				}
    				
    				chart.options.data[0].dataPoints = data;
    				chart.render();	
    			});
    			var updateChart = function() {
    			            
    				$.getJSON("data_1.php", function (data) {
    					chart.options.data[0].dataPoints = data;
    					chart.render();
    				});
    			}            
    			setInterval(function(){updateChart()},1000);
    		}
    	</script>
Viewing 1 post (of 1 total)