score:3
Accepted answer
Use tooltipItem property index to reference the item in your tooltipsLabel array:
var tooltipsLabel = ['Dhaka', 'Rajshahi', 'NewYork', 'London']
var chartList = [5, 6, 7, 8];
function chart() {
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["Red", "Blue", "green", "Yellow"],
datasets: [{
label: '# of Votes',
data: chartList,
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
},
tooltips: {
mode: 'index',
intersect: true,
callbacks: {
title: function(tooltipItem, data) {
console.log(tooltipItem);
return tooltipsLabel[tooltipItem[0].index];
}
}
}
}
});
}
chart();
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row">
<div class="col-lg-4">
<canvas id="myChart" width="100" height="100"></canvas>
</div>
<div class="col-lg-4"><canvas id="pieChart" width="100" height="100"></canvas></div>
</div>
Source: stackoverflow.com
Related Query
- Adding custom title in tooltips of chart.js
- Adding custom text to Bar Chart label values using Chart.js
- Custom Tooltips On Line Chart Using Chart.js
- How to edit my custom tooltips in my line chart using chart.js?
- Charts.js v2: always show custom (html) tooltips on chart
- Chart JS Custom tooltips with % and label for X and Y axles
- Chart JS custom tooltip option?
- How do you hide the title of a chart tooltip?
- chartjs : how to set custom scale in bar chart
- Adding trendlines to existing chart Chart.js
- Adding a Title to a Chart.js line graph
- custom tooltips with react-chartjs-2 library
- Chart.js, adding footer to chart
- Is it possible to add a custom font to chart js?
- Adding Chart.js line chart to Jinja2/Flask html page from JS file
- Chart.js HTML custom legend issues with doughnut chart
- Remove the label and show only value in tooltips of a bar chart
- Adding a label to a doughnut chart in Chart.js shows all values in each chart
- how to add a title to my ng2-charts bar chart
- Extending Line Chart with custom line
- Chart.js - Creating Custom Chart Types
- Chart js: how can I align the legend and the title
- How do you add custom text to tooltips in charts.js
- Add a custom label to the top or bottom of a stacked bar chart
- Chart JS custom tooltip not showing
- Custom data in label on ChartJS pie chart
- How to draw a needle on a custom donut chart and add datapoints to the needle?
- Custom data position on the doughnut chart in chart.js
- How can I create custom tooltips for each data point in a graph?
- Always display ChartJS custom tooltips
More Query from same tag
- drawing bar chart with Chart.js
- JavaScript Error - Uncaught SyntaxError: Unexpected number
- Relative bar chart overlay on line chart in chart.js
- generating a Chart.js chart with python data
- Adding image on chart js
- Why is my Chart.JS canvas not destroying?
- Display data at ends of floating bar graph (created using chart js)
- Angular-charts/Chart.js is not working
- Chart.js 2 - Axis Layer Padding
- How to disable scientific notations in logarithmic chart type
- Chart.js after ajax refresh there are two charts in the same container (new and old)
- React using fetch returns undefined until save
- Prevent size of canvas chart js to equal window height and width
- Chart.js Passing an array starting with 1 instead of 0 problem
- Vue and Chartjs - Running a simple example of vue-chartjs
- Chart.js Legend Customization
- Chart js vertical line z-index
- ChartJS 2.6 - Bar chart fixed height scrollable-X
- Chartjs not showing up in Foundation5 Tabs
- Angular CharJS option tooltip label did not work
- How to set max/min on x axis to display time range in Chart.js?
- How to print a chart rendered by code
- Data will not draw onto my chart
- Charts js only showing 2 data points on sparkline
- I have 10 points inn x-axis, ranging [-25,-20,,-15,-10,0,10,20,30,40,50]. But I want my line chart to start from -15 of x-axis. How we can achieve?
- generate basic pie chart using chartjs
- Chart.js Bar Chart coloring Technique
- Chart js label issue in react js
- Chart.js only appears randomly, and disappears on page refresh
- How to add afterDataLimits callback to chart.js