1
Oops, I’m using the Chartjs for graphic generation, I am integrating with PHP to send json to the chart
php
$arrLabels = array("January","February","March");
$arrDatasets = array('label' => "My First dataset",'fillColor' => "rgba(220,220,220,0.2)", 'strokeColor' => "rgba(220,220,220,1)", 'pointColor' => "rgba(220,220,220,1)", 'pointStrokeColor' => "#fff", 'pointHighlightFill' => "#fff", 'pointHighlightStroke' => "rgba(220,220,220,1)", 'data' => array('28', '48', '40'));
$arrReturn = array(array('labels' => $arrLabels, 'datasets' => $arrDatasets));
print (json_encode($arrReturn));
js
var ctx = document.getElementById("salesChart");
var myChart = new Chart(ctx, {
type: 'line',
data: {
data_retorno
}
});
Value of data_retorno
[
{
"labels":[
"January",
"February",
"March"
],
"datasets":{
"label":"My First dataset",
"fillColor":"rgba(220,220,220,0.2)",
"strokeColor":"rgba(220,220,220,1)",
"pointColor":"rgba(220,220,220,1)",
"pointStrokeColor":"#fff",
"pointHighlightFill":"#fff",
"pointHighlightStroke":"rgba(220,220,220,1)",
"data":[
"28",
"48",
"40"
]
}
}
]
Where data_retorno
is the return of the ajax.
The graph that is already loaded with other data, when receiving this result, simply the lines disappear and nothing happens
Maybe the
data_retorno
is not in the format chartjs expects. You can share with us the value ofdata_retorno
?– BrTkCa
Opa @Lucascosta edited the question adding the value of
data_retorno
, vlw– sNniffer
try
data: data_retorno[0]
@sNniffer– BrTkCa
@Lucascosta gave Chart.js error, error:
TypeError: can't assign to properties of (new String(" ")): not an object
– sNniffer