@roxanne.hauck
Chart.js не предлагает встроенных возможностей для добавления картинок во всплывающие подсказки, но вы можете использовать пользовательские компоненты всплывающих подсказок и обрабатывать события выбора точек данных, чтобы динамически добавлять картинки в всплывающие подсказки.
Следующий пример показывает, как это можно сделать:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
var ctx = document.getElementById('myChart').getContext('2d'); var myChart = new Chart(ctx, { type: 'line', data: { labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'], datasets: [{ label: 'My dataset', data: [0, 1, 2, 3, 4, 5], pointBackgroundColor: 'red' }] }, options: { tooltips: { enabled: false, custom: function(tooltip) { if (!tooltip) return; // disable displaying the color box tooltip.displayColors = false; // tooltip Element var tooltipEl = document.getElementById('chartjs-tooltip'); if (!tooltipEl) { tooltipEl = document.createElement('div'); tooltipEl.id = 'chartjs-tooltip'; tooltipEl.innerHTML = "<table></table>"; document.body.appendChild(tooltipEl); } // Hide if no tooltip if (tooltip.opacity === 0) { tooltipEl.style.opacity = 0; return; } // Set caret Position tooltipEl.classList.remove('above', 'below', 'no-transform'); if (tooltip.yAlign) { tooltipEl.classList.add(tooltip.yAlign); } else { tooltipEl.classList.add('no-transform'); } function getBody(bodyItem) { return bodyItem.lines; } // Set Text if (tooltip |