Chartjs: dynamic data (array) not working
In my recent work, I'm implementing ChartJS charts.
But I'm having trouble popularizing the graph with the data I get from the database.
What I am trying to do:
I get the data from the database, and I send the information I want for an Array.
And I'm pulling the Array in the field I want to use.
Here is my code js:
function charts()
var ligEntrantes = ;
var registeredOrders = ;
var duvidasRegistradas = ;
var incidentesRegistrados = ;
$.ajax(
url: '<?=base_url("/relatorios/auxiliar")?>',
dataType: 'json',
success: function(response)
$(response.information).each(function(index, item)
ligEntrantes.push(item.incomingCalls);
registeredOrders.push(item.registeredOrders);
duvidasRegistradas.push(item.doubt);
incidentesRegistrados.push(item.incidents);
);
console.log(ligEntrantes);
,
error: function(response)
console.error(response);
)
Chart.defaults.global.hover.intersect = false;
var estados = ["Acre","Alagoas","Amapá","Amazonas","Bahia","Ceará","Distrito Federal","Espírito Santo","Goiás","Maranhão","Mato Grosso","Mato Grosso do Sul","Minas Gerais","Pará","Paraíba","Paraná","Pernambuco","Piauí","Rio de Janeiro","Rio Grande do Norte","Rio Grande do Sul","Rondônia","Roraima","Santa Catarina","São Paulo","Sergipe","Tocantins"];
var regionChartCanvas = document.getElementById("regionChart").getContext("2d");
var regionChart = new Chart(regionChartCanvas,
type: 'line',
data:
labels: estados,
datasets: [
label: 'Ligações Entrantes',
data: ligEntrantes,
backgroundColor: 'transparent',
borderColor: 'rgba(46, 204, 113,1.0)',
pointHoverBackgroundColor: 'rgba(46, 204, 113,1.0)',
lineTension: 0
,
label: 'Pedidos Registradas',
data: registeredOrders,
backgroundColor: 'transparent',
borderColor: 'rgba(52, 152, 219,1.0)',
pointHoverBackgroundColor: 'rgba(52, 152, 219,1.0)',
lineTension: 0
,
label: 'Dúvidas Registradas',
data: duvidasRegistradas,
backgroundColor: 'transparent',
borderColor: 'rgba(52, 73, 94,1.0)',
pointHoverBackgroundColor: 'rgba(52, 73, 94,1.0)',
lineTension: 0
,
label: 'Incidentes Registradas',
data: incidentesRegistrados,
backgroundColor: 'transparent',
borderColor: 'rgba(231, 76, 60,1.0)',
pointHoverBackgroundColor: 'rgba(231, 76, 60,1.0)',
lineTension: 0
]
,
options:
animation: false,
scales:
yAxes: [
stacked: true,
autoSkip: false,
beginAtZero: true
],
xAxes: [
ticks:
autoSkip: false
]
,
tooltips:
mode: 'x',
displayColors: true
,
);
;
However, when loading the page, the graph is not generated.
And when I move the mouse over the graph, I get the error in the console:
Uncaught TypeError: Cannot read property 'skip' of undefined --------- Chart.min.js:10
I've done tests with console.log in several parts of the code, and the Array is recognized normally.
Could someone please help me?
Grateful for disposal.
jquery chart.js
add a comment |
In my recent work, I'm implementing ChartJS charts.
But I'm having trouble popularizing the graph with the data I get from the database.
What I am trying to do:
I get the data from the database, and I send the information I want for an Array.
And I'm pulling the Array in the field I want to use.
Here is my code js:
function charts()
var ligEntrantes = ;
var registeredOrders = ;
var duvidasRegistradas = ;
var incidentesRegistrados = ;
$.ajax(
url: '<?=base_url("/relatorios/auxiliar")?>',
dataType: 'json',
success: function(response)
$(response.information).each(function(index, item)
ligEntrantes.push(item.incomingCalls);
registeredOrders.push(item.registeredOrders);
duvidasRegistradas.push(item.doubt);
incidentesRegistrados.push(item.incidents);
);
console.log(ligEntrantes);
,
error: function(response)
console.error(response);
)
Chart.defaults.global.hover.intersect = false;
var estados = ["Acre","Alagoas","Amapá","Amazonas","Bahia","Ceará","Distrito Federal","Espírito Santo","Goiás","Maranhão","Mato Grosso","Mato Grosso do Sul","Minas Gerais","Pará","Paraíba","Paraná","Pernambuco","Piauí","Rio de Janeiro","Rio Grande do Norte","Rio Grande do Sul","Rondônia","Roraima","Santa Catarina","São Paulo","Sergipe","Tocantins"];
var regionChartCanvas = document.getElementById("regionChart").getContext("2d");
var regionChart = new Chart(regionChartCanvas,
type: 'line',
data:
labels: estados,
datasets: [
label: 'Ligações Entrantes',
data: ligEntrantes,
backgroundColor: 'transparent',
borderColor: 'rgba(46, 204, 113,1.0)',
pointHoverBackgroundColor: 'rgba(46, 204, 113,1.0)',
lineTension: 0
,
label: 'Pedidos Registradas',
data: registeredOrders,
backgroundColor: 'transparent',
borderColor: 'rgba(52, 152, 219,1.0)',
pointHoverBackgroundColor: 'rgba(52, 152, 219,1.0)',
lineTension: 0
,
label: 'Dúvidas Registradas',
data: duvidasRegistradas,
backgroundColor: 'transparent',
borderColor: 'rgba(52, 73, 94,1.0)',
pointHoverBackgroundColor: 'rgba(52, 73, 94,1.0)',
lineTension: 0
,
label: 'Incidentes Registradas',
data: incidentesRegistrados,
backgroundColor: 'transparent',
borderColor: 'rgba(231, 76, 60,1.0)',
pointHoverBackgroundColor: 'rgba(231, 76, 60,1.0)',
lineTension: 0
]
,
options:
animation: false,
scales:
yAxes: [
stacked: true,
autoSkip: false,
beginAtZero: true
],
xAxes: [
ticks:
autoSkip: false
]
,
tooltips:
mode: 'x',
displayColors: true
,
);
;
However, when loading the page, the graph is not generated.
And when I move the mouse over the graph, I get the error in the console:
Uncaught TypeError: Cannot read property 'skip' of undefined --------- Chart.min.js:10
I've done tests with console.log in several parts of the code, and the Array is recognized normally.
Could someone please help me?
Grateful for disposal.
jquery chart.js
add a comment |
In my recent work, I'm implementing ChartJS charts.
But I'm having trouble popularizing the graph with the data I get from the database.
What I am trying to do:
I get the data from the database, and I send the information I want for an Array.
And I'm pulling the Array in the field I want to use.
Here is my code js:
function charts()
var ligEntrantes = ;
var registeredOrders = ;
var duvidasRegistradas = ;
var incidentesRegistrados = ;
$.ajax(
url: '<?=base_url("/relatorios/auxiliar")?>',
dataType: 'json',
success: function(response)
$(response.information).each(function(index, item)
ligEntrantes.push(item.incomingCalls);
registeredOrders.push(item.registeredOrders);
duvidasRegistradas.push(item.doubt);
incidentesRegistrados.push(item.incidents);
);
console.log(ligEntrantes);
,
error: function(response)
console.error(response);
)
Chart.defaults.global.hover.intersect = false;
var estados = ["Acre","Alagoas","Amapá","Amazonas","Bahia","Ceará","Distrito Federal","Espírito Santo","Goiás","Maranhão","Mato Grosso","Mato Grosso do Sul","Minas Gerais","Pará","Paraíba","Paraná","Pernambuco","Piauí","Rio de Janeiro","Rio Grande do Norte","Rio Grande do Sul","Rondônia","Roraima","Santa Catarina","São Paulo","Sergipe","Tocantins"];
var regionChartCanvas = document.getElementById("regionChart").getContext("2d");
var regionChart = new Chart(regionChartCanvas,
type: 'line',
data:
labels: estados,
datasets: [
label: 'Ligações Entrantes',
data: ligEntrantes,
backgroundColor: 'transparent',
borderColor: 'rgba(46, 204, 113,1.0)',
pointHoverBackgroundColor: 'rgba(46, 204, 113,1.0)',
lineTension: 0
,
label: 'Pedidos Registradas',
data: registeredOrders,
backgroundColor: 'transparent',
borderColor: 'rgba(52, 152, 219,1.0)',
pointHoverBackgroundColor: 'rgba(52, 152, 219,1.0)',
lineTension: 0
,
label: 'Dúvidas Registradas',
data: duvidasRegistradas,
backgroundColor: 'transparent',
borderColor: 'rgba(52, 73, 94,1.0)',
pointHoverBackgroundColor: 'rgba(52, 73, 94,1.0)',
lineTension: 0
,
label: 'Incidentes Registradas',
data: incidentesRegistrados,
backgroundColor: 'transparent',
borderColor: 'rgba(231, 76, 60,1.0)',
pointHoverBackgroundColor: 'rgba(231, 76, 60,1.0)',
lineTension: 0
]
,
options:
animation: false,
scales:
yAxes: [
stacked: true,
autoSkip: false,
beginAtZero: true
],
xAxes: [
ticks:
autoSkip: false
]
,
tooltips:
mode: 'x',
displayColors: true
,
);
;
However, when loading the page, the graph is not generated.
And when I move the mouse over the graph, I get the error in the console:
Uncaught TypeError: Cannot read property 'skip' of undefined --------- Chart.min.js:10
I've done tests with console.log in several parts of the code, and the Array is recognized normally.
Could someone please help me?
Grateful for disposal.
jquery chart.js
In my recent work, I'm implementing ChartJS charts.
But I'm having trouble popularizing the graph with the data I get from the database.
What I am trying to do:
I get the data from the database, and I send the information I want for an Array.
And I'm pulling the Array in the field I want to use.
Here is my code js:
function charts()
var ligEntrantes = ;
var registeredOrders = ;
var duvidasRegistradas = ;
var incidentesRegistrados = ;
$.ajax(
url: '<?=base_url("/relatorios/auxiliar")?>',
dataType: 'json',
success: function(response)
$(response.information).each(function(index, item)
ligEntrantes.push(item.incomingCalls);
registeredOrders.push(item.registeredOrders);
duvidasRegistradas.push(item.doubt);
incidentesRegistrados.push(item.incidents);
);
console.log(ligEntrantes);
,
error: function(response)
console.error(response);
)
Chart.defaults.global.hover.intersect = false;
var estados = ["Acre","Alagoas","Amapá","Amazonas","Bahia","Ceará","Distrito Federal","Espírito Santo","Goiás","Maranhão","Mato Grosso","Mato Grosso do Sul","Minas Gerais","Pará","Paraíba","Paraná","Pernambuco","Piauí","Rio de Janeiro","Rio Grande do Norte","Rio Grande do Sul","Rondônia","Roraima","Santa Catarina","São Paulo","Sergipe","Tocantins"];
var regionChartCanvas = document.getElementById("regionChart").getContext("2d");
var regionChart = new Chart(regionChartCanvas,
type: 'line',
data:
labels: estados,
datasets: [
label: 'Ligações Entrantes',
data: ligEntrantes,
backgroundColor: 'transparent',
borderColor: 'rgba(46, 204, 113,1.0)',
pointHoverBackgroundColor: 'rgba(46, 204, 113,1.0)',
lineTension: 0
,
label: 'Pedidos Registradas',
data: registeredOrders,
backgroundColor: 'transparent',
borderColor: 'rgba(52, 152, 219,1.0)',
pointHoverBackgroundColor: 'rgba(52, 152, 219,1.0)',
lineTension: 0
,
label: 'Dúvidas Registradas',
data: duvidasRegistradas,
backgroundColor: 'transparent',
borderColor: 'rgba(52, 73, 94,1.0)',
pointHoverBackgroundColor: 'rgba(52, 73, 94,1.0)',
lineTension: 0
,
label: 'Incidentes Registradas',
data: incidentesRegistrados,
backgroundColor: 'transparent',
borderColor: 'rgba(231, 76, 60,1.0)',
pointHoverBackgroundColor: 'rgba(231, 76, 60,1.0)',
lineTension: 0
]
,
options:
animation: false,
scales:
yAxes: [
stacked: true,
autoSkip: false,
beginAtZero: true
],
xAxes: [
ticks:
autoSkip: false
]
,
tooltips:
mode: 'x',
displayColors: true
,
);
;
However, when loading the page, the graph is not generated.
And when I move the mouse over the graph, I get the error in the console:
Uncaught TypeError: Cannot read property 'skip' of undefined --------- Chart.min.js:10
I've done tests with console.log in several parts of the code, and the Array is recognized normally.
Could someone please help me?
Grateful for disposal.
jquery chart.js
jquery chart.js
asked Nov 13 '18 at 11:54
Rodrigo Roberto de AlmeidaRodrigo Roberto de Almeida
34
34
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
ChartJS doesn't have "regionChart" support. Following link have the list of supported charts using ChartJS. I will suggest you to first implement a chart using hard coded values and when you are able to draw chart with hard coded then in next next step pull the data from the DB.
ChartJS charts
regionChart is the name of my chart.
– Rodrigo Roberto de Almeida
Nov 13 '18 at 13:10
My bad, I just read the name and assumed that you want to draw this type of chat and didn't noticed the type. However, your code is working fine. I am able to run it and your chart is drawn. I have assigned hard coded values to your arrays "ligEntrantes, registeredOrders,...". Just do one thing do call your function on page load. I called it like $(document).ready(function() charts(); );
– Muhammad Rahil Rafiq
Nov 14 '18 at 11:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280502%2fchartjs-dynamic-data-array-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
ChartJS doesn't have "regionChart" support. Following link have the list of supported charts using ChartJS. I will suggest you to first implement a chart using hard coded values and when you are able to draw chart with hard coded then in next next step pull the data from the DB.
ChartJS charts
regionChart is the name of my chart.
– Rodrigo Roberto de Almeida
Nov 13 '18 at 13:10
My bad, I just read the name and assumed that you want to draw this type of chat and didn't noticed the type. However, your code is working fine. I am able to run it and your chart is drawn. I have assigned hard coded values to your arrays "ligEntrantes, registeredOrders,...". Just do one thing do call your function on page load. I called it like $(document).ready(function() charts(); );
– Muhammad Rahil Rafiq
Nov 14 '18 at 11:19
add a comment |
ChartJS doesn't have "regionChart" support. Following link have the list of supported charts using ChartJS. I will suggest you to first implement a chart using hard coded values and when you are able to draw chart with hard coded then in next next step pull the data from the DB.
ChartJS charts
regionChart is the name of my chart.
– Rodrigo Roberto de Almeida
Nov 13 '18 at 13:10
My bad, I just read the name and assumed that you want to draw this type of chat and didn't noticed the type. However, your code is working fine. I am able to run it and your chart is drawn. I have assigned hard coded values to your arrays "ligEntrantes, registeredOrders,...". Just do one thing do call your function on page load. I called it like $(document).ready(function() charts(); );
– Muhammad Rahil Rafiq
Nov 14 '18 at 11:19
add a comment |
ChartJS doesn't have "regionChart" support. Following link have the list of supported charts using ChartJS. I will suggest you to first implement a chart using hard coded values and when you are able to draw chart with hard coded then in next next step pull the data from the DB.
ChartJS charts
ChartJS doesn't have "regionChart" support. Following link have the list of supported charts using ChartJS. I will suggest you to first implement a chart using hard coded values and when you are able to draw chart with hard coded then in next next step pull the data from the DB.
ChartJS charts
answered Nov 13 '18 at 12:33
Muhammad Rahil RafiqMuhammad Rahil Rafiq
614
614
regionChart is the name of my chart.
– Rodrigo Roberto de Almeida
Nov 13 '18 at 13:10
My bad, I just read the name and assumed that you want to draw this type of chat and didn't noticed the type. However, your code is working fine. I am able to run it and your chart is drawn. I have assigned hard coded values to your arrays "ligEntrantes, registeredOrders,...". Just do one thing do call your function on page load. I called it like $(document).ready(function() charts(); );
– Muhammad Rahil Rafiq
Nov 14 '18 at 11:19
add a comment |
regionChart is the name of my chart.
– Rodrigo Roberto de Almeida
Nov 13 '18 at 13:10
My bad, I just read the name and assumed that you want to draw this type of chat and didn't noticed the type. However, your code is working fine. I am able to run it and your chart is drawn. I have assigned hard coded values to your arrays "ligEntrantes, registeredOrders,...". Just do one thing do call your function on page load. I called it like $(document).ready(function() charts(); );
– Muhammad Rahil Rafiq
Nov 14 '18 at 11:19
regionChart is the name of my chart.
– Rodrigo Roberto de Almeida
Nov 13 '18 at 13:10
regionChart is the name of my chart.
– Rodrigo Roberto de Almeida
Nov 13 '18 at 13:10
My bad, I just read the name and assumed that you want to draw this type of chat and didn't noticed the type. However, your code is working fine. I am able to run it and your chart is drawn. I have assigned hard coded values to your arrays "ligEntrantes, registeredOrders,...". Just do one thing do call your function on page load. I called it like $(document).ready(function() charts(); );
– Muhammad Rahil Rafiq
Nov 14 '18 at 11:19
My bad, I just read the name and assumed that you want to draw this type of chat and didn't noticed the type. However, your code is working fine. I am able to run it and your chart is drawn. I have assigned hard coded values to your arrays "ligEntrantes, registeredOrders,...". Just do one thing do call your function on page load. I called it like $(document).ready(function() charts(); );
– Muhammad Rahil Rafiq
Nov 14 '18 at 11:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280502%2fchartjs-dynamic-data-array-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown