I have a Dashboard made in PHP and I use the Chart.js library.
In the Dashboard, I have some graphics that are fed into PHP, like in this example:
AndI'mhavingaquestion,whenIclickonsomecolumnofthegraph,IwanttogetitsnameanddisplayitinanJSalertmyself.
Inshort,whenIclickonabarbelongingtotheG1,Iwantittoshowanalertonitsname,Example:"You clicked on G1". The same with G4 or whatever else you have on the chart. How can I do this?
HTML Code:
<div class="box-body">
<canvas id="grupo" height="80px"></canvas>
</div>
JS Code:
var ctx5 = document.getElementById("grupo").getContext('2d');
var container5 = new Chart(ctx5, {
type: 'bar',
data: {
labels: label_grupo, // variavel alimentada pelo PHP
datasets: [{
label: "Total",
backgroundColor: '#4dbd74',
data: data_grupo_total, // variavel alimentada pelo PHP
}, {
label: "Alfa",
backgroundColor: '#20a8d8',
data: data_grupo_macho, // variavel alimentada pelo PHP
}, {
label: "Beta",
backgroundColor: '#4c4c4c',
data: data_grupo_femea, // variavel alimentada pelo PHP
}]
},
options: {
tooltips: {
mode: 'index',
intersect: false
},
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: "Quantidade"
}
}],
xAxes: [{
gridLines: {
color: "rgba(0, 0, 0, 0)",
},
ticks: {
autoSkip: false,
fontSize: 11,
beginAtZero:true
}
}]
},
legend: {
labels: {
boxWidth: 12
},
position: "bottom",
},
}
});