Hi,
I have the date in a CSV file, I am reading in php, I am not able to convert date (Ex: 05/01/2016) to a format readable by canvas JS. The Date function is PHP is not working. Can someone please help?
<?php
$dataPoints1 = $dataPoints2 = array();
$csv = array_map(‘str_getcsv’, file(‘UUdata.csv’));
for($i=1;$i<count($csv);$i++)
{
//$x_axis = date(‘m-d-Y’,strtotime($csv[$i][0]));
//$x_axis = date(‘D M d Y H:i:s O’, strtotime($csv[$i][0]));
$y_2016uu = bd_nice_number($csv[$i][4]);
$y_2017uu = bd_nice_number($csv[$i][5]);
array_push($dataPoints1, array(“x” => $x_axis, “y” => $y_2016uu));
array_push($dataPoints2, array(“x” => $x_axis, “y” => $y_2017uu));
}
Here is the js code:
$(function () {
var chart = new CanvasJS.Chart(“chartContainer”, {
theme: “theme2”,
zoomEnabled: true,
animationEnabled: true,
title: {
text: “Line Chart”
},
subtitles:[
{ text: “” }
],
data: [
{
type: “line”,
dataPoints: <?php echo json_encode($dataPoints1); ?>
},
{
type: “line”,
dataPoints: <?php echo json_encode($dataPoints2); ?>
}
]
});
chart.render();
});