Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit 58fd677

Browse files
committed
Improved chart labels on hover
1 parent 25083cd commit 58fd677

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

php/load/graphs/BarDayTimes.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ function createGraph(combiData, plainData, singleDayData, canvas){
7070
type: 'bar',
7171
data: chartData,
7272
options: {
73-
responsive: true
73+
responsive: true,
74+
tooltips: {
75+
callbacks: {
76+
label: function(tooltipItem, chartData) {
77+
return `${chartData.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]} hours`;
78+
}
79+
}
80+
}
7481
}
7582
};
7683
return new Chart(canvas, config);

php/load/graphs/BarDays.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ function createGraph(combiData, plainData, singleDayData, canvas){
4949
type: 'bar',
5050
data: chartData,
5151
options: {
52-
responsive: true
52+
responsive: true,
53+
tooltips: {
54+
callbacks: {
55+
label: function(tooltipItem, chartData) {
56+
return `${chartData.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]} hours`;
57+
}
58+
}
59+
}
5360
}
5461
};
5562
return new Chart(canvas, config);

php/load/graphs/PieCategory.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ function createGraph(combiData, plainData, singleDayData, canvas){
3838
labels: Object.keys(plotdata)
3939
},
4040
options: {
41-
responsive: true
41+
responsive: true,
42+
tooltips: {
43+
callbacks: {
44+
label: function(tooltipItem, chartData) {
45+
return chartData.labels[tooltipItem.index] + ': ' +
46+
chartData.datasets[0].data[tooltipItem.index] + ' hours';
47+
}
48+
}
49+
}
4250
}
4351
};
4452
return new Chart(canvas, config);

php/load/graphs/PieTask.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ function createGraph(combiData, plainData, singleDayData, canvas){
3838
labels: Object.keys(plotdata)
3939
},
4040
options: {
41-
responsive: true
41+
responsive: true,
42+
tooltips: {
43+
callbacks: {
44+
label: function(tooltipItem, chartData) {
45+
return chartData.labels[tooltipItem.index] + ': ' +
46+
chartData.datasets[0].data[tooltipItem.index] + ' hours';
47+
}
48+
}
49+
}
4250
}
4351
};
4452
return new Chart(canvas, config);

0 commit comments

Comments
 (0)