Skip to content

Commit 379135e

Browse files
authored
Merge pull request #10 from coreui/fix-custom-tooltips
fix: custom tooltips do not show fix: scales.[x/y]Axes.barPercentage is deprecated
2 parents 654ee81 + a7fa8a3 commit 379135e

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

resources/js/coreui/main.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ Chart.defaults.global.pointHitDetectionRadius = 1
1414
Chart.defaults.global.tooltips.enabled = false
1515
Chart.defaults.global.tooltips.mode = 'index'
1616
Chart.defaults.global.tooltips.position = 'nearest'
17-
Chart.defaults.global.tooltips.custom = coreui.ChartJS.CustomTooltips
17+
Chart.defaults.global.tooltips.custom = coreui.ChartJS.customTooltips
1818
Chart.defaults.global.defaultFontColor = '#646470'
19+
Chart.defaults.global.responsiveAnimationDuration = 1
1920

2021
document.body.addEventListener('classtoggle', event => {
2122
if (event.detail.className === 'c-dark-theme') {
@@ -192,9 +193,10 @@ const cardChart4 = new Chart(document.getElementById('card-chart4'), {
192193
label: 'My First dataset',
193194
backgroundColor: 'rgba(255,255,255,.2)',
194195
borderColor: 'rgba(255,255,255,.55)',
195-
data: [78, 81, 80, 45, 34, 12, 40, 85, 65, 23, 12, 98, 34, 84, 67, 82]
196+
data: [78, 81, 80, 45, 34, 12, 40, 85, 65, 23, 12, 98, 34, 84, 67, 82],
197+
barPercentage: 0.7
196198
}
197-
]
199+
],
198200
},
199201
options: {
200202
maintainAspectRatio: false,
@@ -203,8 +205,7 @@ const cardChart4 = new Chart(document.getElementById('card-chart4'), {
203205
},
204206
scales: {
205207
xAxes: [{
206-
display: false,
207-
barPercentage: 0.6
208+
display: false
208209
}],
209210
yAxes: [{
210211
display: false
@@ -273,6 +274,14 @@ const mainChart = new Chart(document.getElementById('main-chart'), {
273274
hoverRadius: 4,
274275
hoverBorderWidth: 3
275276
}
277+
},
278+
tooltips: {
279+
intersect: true,
280+
callbacks: {
281+
labelColor: function(tooltipItem, chart) {
282+
return { backgroundColor: chart.data.datasets[tooltipItem.datasetIndex].borderColor };
283+
}
284+
}
276285
}
277286
}
278287
})

resources/js/coreui/widgets.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Chart.defaults.global.pointHitDetectionRadius = 1
1313
Chart.defaults.global.tooltips.enabled = false
1414
Chart.defaults.global.tooltips.mode = 'index'
1515
Chart.defaults.global.tooltips.position = 'nearest'
16-
Chart.defaults.global.tooltips.custom = coreui.ChartJS.CustomTooltips
16+
Chart.defaults.global.tooltips.custom = coreui.ChartJS.customTooltips
1717

1818
document.body.addEventListener('classtoggle', event => {
1919
if (event.detail.className === 'c-dark-theme') {
@@ -187,7 +187,8 @@ const cardChart4 = new Chart(document.getElementById('card-chart4'), {
187187
label: 'My First dataset',
188188
backgroundColor: 'rgba(255,255,255,.2)',
189189
borderColor: 'rgba(255,255,255,.55)',
190-
data: [78, 81, 80, 45, 34, 12, 40, 85, 65, 23, 12, 98, 34, 84, 67, 82]
190+
data: [78, 81, 80, 45, 34, 12, 40, 85, 65, 23, 12, 98, 34, 84, 67, 82],
191+
barPercentage: 0.7
191192
}
192193
]
193194
},
@@ -198,8 +199,7 @@ const cardChart4 = new Chart(document.getElementById('card-chart4'), {
198199
},
199200
scales: {
200201
xAxes: [{
201-
display: false,
202-
barPercentage: 0.6
202+
display: false
203203
}],
204204
yAxes: [{
205205
display: false

0 commit comments

Comments
 (0)