I am trying to create a candlestick graph with CanvasJs and I am currently having trouble formatting the X Axis correct to show the dates.
I am pulling this data from a database. When I pull the date from the data base I am pulling it as a UNIX Timestamp. I want the X-Axis to show the date for each data point (I want to just do it monthly but I'll worry about that later once I get this). I have tried using "label" and "x" for the date points on the X-Axis.
array_push($dataPoints, array("label"=>$row->day, "y"=> array($row->openPrice, $row->high, $row->low, $row->closePrice)));.
And here is what I have for creating the graph. window.onload = function() {
var chart = new CanvasJS.Chart("chartContainer", {
zoomEnabled:true,
title: {
text: "Apple Historical Prices"
},
axisX: {
labelFormatter: function (e) {
return CanvasJS.formatDate( e.value, "DD MMM");
},
valueFormatString: "DD MMM"
},
axisY: {
includeZero: false,
prefix: "$"
},
data: [{
type: "candlestick",
xValueType: "dateTime",
yValueFormatString: "$###.##",
dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
}]
});
chart.render();
}
What would I have to change here to correctly format the X-Axis to show the date (convert from UNIX Time Stamp)
Currently it only displays "DEC 31" for each data point.