1👍
You are setting the data incorrectly.
You should use
data: [
$arrStemmer[0],
$arrStemmer[1],
$arrStemmer[2],
$Snit_Vaerdi
],
Instead of
data: [
[$arrStemmer[0]],
[$arrStemmer[1]],
[$arrStemmer[2]],
[$Snit_Vaerdi]
],
- Chartjs-Iterating over an array of objects and stack a Chart JS Bar?
- Chartjs-How to pass function variable from one file to another in react
0👍
This should work. if the $arrStemmer
and $snit_Vaerdi
are filled.
let $stemmer = document.getElementById('can_afstemning_graf').getContext('2d');
let myChart = new Chart($stemmer, {
type: 'bar',
data: {
labels: ['Super mad', 'Middel', 'Ikke ok', 'Gennemsnit'],
datasets: [{
label: 'Antal stemmer',
data: [
$arrStemmer[0],
$arrStemmer[1],
$arrStemmer[2],
$Snit_Vaerdi
],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
- Chartjs-How to hide the tick marks of the axis in react-chartjs-2
- Chartjs-Two charts in a page not working, using Chart.js 3.1.1 cdn in Laravel 8.x framework
Source:stackexchange.com