Hi This is my code, I am using Ajax for Displaying Chart
Below is index.php (I am trying to display chart in this page)
$(document).ready(function() {
var fromDate = document.getElementById('fromDate').value;
var toDate = document.getElementById('toDate').value;
$("#rangeButton").click(function(){
var clickBtnValue = $(this).val();
//alert(clickBtnValue);
//alert(fromDate + ' '+toDate);
var ajaxurl = 'dbconnect.php',
data = {'action': clickBtnValue, 'from': fromDate, 'to' : toDate, dataType: 'json'};
$.post(ajaxurl, data, function (response) {
alert(response);
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
data: [
{
type: "spline",
dataPoints: response
}
]
});
chart.render();
});
});
Below is dbconnect.php (Fetching Data from DB)
$data_points = array();
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
$point = array('label' => $row['date'] , 'y' => $row['value']);
array_push($data_points, $point);
}
echo json_encode($data_points, JSON_NUMERIC_CHECK);
The response which I received is
[{"label":"2015-09-13","y":"10"},{"label":"2015-09-14","y":"20"},{"label":"2015-09-10","y":"70"},{"label":"2015-09-11","y":"80"}]
Everything was correct, but chart was not displayed. When I give static values, it is working! How to solve this issue?