score:1
You need to define a new tooltip position mode as follows:
Chart.Tooltip.positioners.middle = elements => {
let model = elements[0]._model;
return {
x: model.x,
y: (model.base + model.y) / 2
};
};
Further you have to define tooltips
within the chart options
as follows:
tooltips: {
position: 'middle', // must match the positioner function name defined above
yAlign: null, // to get rid of the pointer
xAlign: 'center'
}
Please take a look at below runnable code snippet and see how it works:
Chart.Tooltip.positioners.middle = elements => {
let model = elements[0]._model;
return {
x: model.x,
y: (model.base + model.y) / 2
};
};
new Chart(document.getElementById("chart"), {
type: "bar",
data: {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: "My Dataset",
data: [65, 59, 80, 81, 56, 55, 40],
backgroundColor: ["rgba(255, 99, 132, 0.2)", "rgba(255, 159, 64, 0.2)", "rgba(255, 205, 86, 0.2)", "rgba(75, 192, 192, 0.2)", "rgba(54, 162, 235, 0.2)", "rgba(153, 102, 255, 0.2)", "rgba(201, 203, 207, 0.2)"],
borderColor: ["rgb(255, 99, 132)", "rgb(255, 159, 64)", "rgb(255, 205, 86)", "rgb(75, 192, 192)", "rgb(54, 162, 235)", "rgb(153, 102, 255)", "rgb(201, 203, 207)"],
borderWidth: 1
}]
},
options: {
tooltips: {
position: 'middle',
yAlign: null,
xAlign: 'center'
},
legend: {
display: false
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js"></script>
<canvas id="chart" height="90"></canvas>
Display the resulting chart in full page mode if the tooltips don't show up in embedded mode.
Source: stackoverflow.com
Related Query
- How to change the position of the tooltip for the Bar type chart in Chart.Js
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- PrimeNg bar chart how to show a label for the y-axis
- How to change the label and grid line position on a timeseries chart in Chart.js 3?
- How to use set the color for each bar in a bar chart using chartjs?
- How can I have different values for the chart and the tooltip in chart.js?
- How can I change the background colors of a bar chart after it has been created?
- Chart.js bar chart change the label position X-axis
- How to add second Y-axis for Bar and Line chart in Chart.js?
- chart js tooltip how to control the data that show
- Chart js. How to change font styles for "labels" array?
- Border radius for the bar chart in ChartJS
- How to change the labels to the image (icon) in bar chart.js
- How do I change the 'months' language displayed on the date axis in Chart JS?
- How to change the cursor to a pointer when I hover over a bar in a ChartJS bar chart?
- Grouping the object by key for Chartjs bar chart
- How to get rid of the white square outline or border in the tooltip for chartjs?
- How to make bar chart animation where all bars grow at the same speed?
- How to change Chart.js horizontal bar chart Width?
- Lift the bar up from the bottom in bar type chart
- In Stacked horizontal bar chart how to remove the vertical line in Chart.js?
- PrimeNg bar chart how do I hide the bar labels?
- How to create a chart that uses strings for both the X and Y axes?
- How to draw outer labels for polar chart using ng2-charts and chart.js at fixed positions outside the rings?
- Chart is too big. How can I reduce size for the chart in vue js?
- How to show different product name for every bar in chart js
- How do I customize y-axis labels and randomly pick the value from the data range for x-axis in Chart js
- angular-chart.js doughnut chart : How do I change width of the arc of a doughnut?
- Change the background color of tooltip dynamically using chart color
- How to draw baseline for bar chart in chart.js
More Query from same tag
- SQL format DATETIME to count months
- how to set chart.js grid color for line chart
- ChartJS / MomentJS - Unable to remove deprecation warning. Graph not showing in firefox/opera
- Chart.js doughnut text colors
- Pie Charts JS: How to set units?
- drawing bar chart with chart.js jQuery
- Resizable/Expendable box annotation in ChartJs
- How can I modify category labels font size in Chart.JS V2?
- ChartJS: Horizontal Bar with multiple datasets not showing Bars
- how to only show zero grid axes at center and hide all other gridlines in chart js
- Chart.js Radar background color of background
- Chart js padding isn't working for data labels
- Chart.js Legend not showing
- ChartJS remove vertical grid lines one on two
- How to update only new data in Chart.JS?
- How to add additional label in the middle of each bar using ChartJS
- ChartJS graph not displaying - line graph
- Different color for each column in angular-chartjs bar chart
- Tooltip background color gets faded angular-chart.js
- Hide labels from pie chart in chartjs
- Cannot make my chart to work with data from mongoDB
- ChartJs multiaxis chart show different label bottom and top
- .destroy() generating error 'window.myChart.destroy()' is not a function
- Responsive ChartJS in Bootstrap Table Cell
- Add buffer to Y axis with chart js
- How to Reset a Chart of Chart.Js?
- Change point size and color on hover in chartjs
- Chart.js - Getting data from HTML
- ChartJs events in Angular
- How should i apply date picker in my chart