hi, i have tried the graph with csv data but it didnt display my data on the graph.
here ismy coding
<!DOCTYPE HTML>
<html>
<head>
<?php
if(isset($_POST['submit'])){
$filename = $_FILES['update_file']['name'];
$file = fopen($filename,"r")
or die('Error occurred when open the file ' . $filename );
$table = array();
while($handle = fgetcsv($file))
{
var_dump($handle);
}
fclose($file);
// $json = json_encode($andle);
?>
<script>
window.onload = function () {
var dataPoints = <?= $handle ?> ;
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
exportEnabled: true,
title:{
text: "Temperature per 5 mins"
},
axisY: {
title: "Temperature",
includeZero: false
},
data: [{
type: "line",
//toolTipContent: "{y} metric tons",
dataPoints: dataPoints
}]
});
//chart.render();
$.get("#update_file", getDataPointsFromCSV);
//var updateInterval = 30000;
//setInterval(function () { updateChart() }, updateInterval);
function getDataPointsFromCSV(csv) {
var csvLines = points = [];
csvLines = csv.split(/[\r?\n|\r|\n]+/);
for (var i = 0; i < csvLines.length; i++) {
if (csvLines[i].length > 0) {
points = csvLines[i].split(",");
dataPoints.push({
label: points[0],
y: parseFloat(points[1])
});
}
}
chart.render();
}
}
</script>
<?php
}
?>
</head>
<body>
<script type="text/javascript" src="https://canvasjs.com/assets/script/jquery-1.11.1.min.js"></script>
<script src="https://cdn.canvasjs.com/canvasjs.min.js"></script>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="update_file"/>
<button type="submit" name="submit">Update</button>
</form>
<br/>
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
</body>
</html>