1
I’m putting together my first chart. When I use date constants Chart renders normally, but when I upload sql database information I don’t have the same success. Follow code ...
<div id="canvas-holder1" style="width: 100%;">
<canvas id="chart1" />
</div>
<script language="javascript" type="text/javascript">
$(function() {
$.ajax({
type: "POST",
url: "Entrada.aspx/getChartData",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: OnErrorCall
});
function OnSuccess(response) {
var lstReceita = eval(response.d[0]);
var lstDespesa = eval(response.d[1]);
var lineChartData = {
labels: ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"],
datasets: [{
label: "Receitas",
data: lstReceita
}, {
label: "Despesas",
data: lstDespesa
}]
};
window.onload = function() {
var chartEl = document.getElementById("chart1");
window.myLine = new Chart(chartEl, {
type: 'line',
data: lineChartData,
options: {
title: {
display: true,
text: 'Comparativo Gráfico de Performance Financeira'
},
tooltips: {
enabled: true
}
}
});
};
};
function OnErrorCall(response) {
alert('error');
}
});
</script>
Remove that
window.onload
, it’s only getting in the way. After that it works? if you don’t have an error in the console?– Sergio
Perfect Sergio. That was exactly the problem.
– Winston
On the testing machine it worked perfectly, but on the hosting provider it did not render. What could that be?
– Winston
Do you have an error in your console? url
"Entrada.aspx/getChartData"
exists and gives some result?– Sergio
The table exists, it has data, the query returns the data, but the json does not complement the work.
– Winston
What gives
console.log(response);
?– Sergio
I didn’t bring anything. It’s a Webmethod. Maybe it needs to be set up on the provider.
– Winston
Okay, so it’s a separate issue from this question and you have to set it up on the server...
– Sergio
Let’s go continue this discussion in chat.
– Winston