0
The code for the chart is in HTML.
In the code below, there are these Abels:
["Área 2","Área 3","Área 7","Área 5","Área 10","Área 8","Área 11","Área 9","Área 1","Área 14"]
According to the date values:
[145,110,100,75,70,70,60,45,40,20],
I managed to make a matrix for:
data: {labels:[MatrizSArea],
And another to:
data: [MatrizSPontos],
But I can’t assemble the chart, the variaces are even loaded but it doesn’t appear correctly on the chart
Follows the code:
function Mychart(){
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {labels:[MatrizSArea],
datasets: [{label: 'SITUAÇÃO CRÍTICA',
data: [MatrizSPontos],
backgroundColor: [
'rgb(255, 0, 0)',
'rgb(255, 0, 0)',
'rgb(255, 0, 0)',
'rgb(191, 143, 0)',
'rgb(191, 143, 0)',
'rgb(255, 255, 0)',
'rgb(255, 255, 0)',
'rgb(0, 176, 80)',
'rgb(0, 176, 80)',
'rgb(0, 176, 80)'
],
}]
},
options: {
title: {
display: true,
text: 'DEPARTAMENTO DE ESTAMPARIA'
},
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
}
Okay, I get it. But how to make the Array dynamic for both values and Labels? Let’s say I have a list and according to the record can change the values and positions of the Abels.
– Valdecir Renkaveski
I updated the answer to a user matrix of Abels as well.. You could.. instead of using 2 arrays as in the example. create an entire object as is the object of the attribute
data
and replace as needed. (I will edit it again with an example like this.. Perai)– Israel Merljak
So, it was very good, but without having to type directly into the code as it would be automatic every time I log in or refresh the page the values and values?
– Valdecir Renkaveski
Dude.. ideally you’re gonna get these values from somewhere, right. It wouldn’t be directly in the code. You could have this data in a database, and when doing a query, return the Abels and values, etc.. You process javascript, mount the Chart object and update.
– Israel Merljak
Now I got date: {Abels: [Matrizsarea], and date: [Matrizspontos], but I can’t use the values that are in the variables to position in the graph.
– Valdecir Renkaveski
@Valdecirrenkaveski friend, the
MatrizSArea
and theMatrizSPontos
are already arrays right? When you say.. Abels: [Matrizsarea] you are effectively placing your list of Abels within a new array. And the same happens with the dots.. tries to remove these brackets so that it stays { Labels: Matrizsarea ... data: Matrizspontos }– Israel Merljak
How to make the values shown when you hover over the columns appear above the columns.
– Valdecir Renkaveski
@Valdecirrenkaveski chartjs-plugin-datalabels
– Israel Merljak
I’d have another way than the one you sent me?
– Valdecir Renkaveski