score:21
This improper cutoff was raised as issue#622 in the Github repository for ChartJS.
This was determined to be a bug (evidently this bug hasn't yet been fixed)
https://github.com/nnnick/Chart.js/issues/622
In response to that issue, Robert Turrall has a solution which he says is a good workaround. Here is his proposed fix:
I'm sure that this is due to the fact that the tooltips are generated within the confines of the canvas, making it difficult to fix.
I had the same issue on my doughnut chart and solved it by implementing custom tooltips as per the example on the samples folder - worked in conjunction with my existing tooltip fontsize and template settings in the chart initialisation code:
var myDoughnutChart = new Chart(donut).Doughnut(donutdata, { tooltipFontSize: 10, tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>hrs", percentageInnerCutout : 70 });
Check out samples/pie-customTooltips.html for the custom tooltip code. Copy/paste and it worked straight away. Very happy!
Tooltip displayed well outside the bounds of the canvas:
PS: there's a line chart example too, which I'm guessing will work fine with bar charts.
score:-1
Interestingly, by the setting the tooltipCaretSize
option to 0
solves the issue.
{ tooltipCaretSize: 0, ... }
score:1
In my case, I was able to work around this issue by reducing the amount of text in the tooltip. I did so using custom tooltip callbacks to specify the label text. My initialization looked like this:
var chart = new Chart(canvas.getContext("2d"), {
type: 'line',
data: chartData,
options: {
responsive: true,
tooltips: {
callbacks: {
title: function(tooltipItems, data) {
return tooltipItems[0].xLabel;
},
label: function(tooltipItems, data) {
return tooltipItems.yLabel;
},
}
},
},
});
There appears to be a fix available that hasn't yet been merged into the project: https://github.com/chartjs/Chart.js/pull/1064
score:2
It seems like Chart.js can't figure out which direction to show the tooltip because it can't detect the size of the tooltip element when it extends beyond the canvas.
In my scenario I fixed it by squeezing the text inside this particular tooltip closer with these options for the tooltip options object:
tooltips.titleMarginBottom = 1;
tooltips.bodySpacing = 1;
tooltips.yPadding = 2;
Wierdly enough Chart.js then correctly decides to show the tooltip to the left of the mouse and not below. Would be cool if you could choose which direction the tooltip appears compared to the mouse.
score:3
I found a workaround for this. I have blank labels on my x axis, so I just added a label with several spaces in it for the last label entry. That caused ChartJS to leave enough space for the label to fit, which also leaves enough room for the tooltip to fit.
In addition, I have large circles for my data points and the last one on the right was getting clipped before. Adding the extra space to the label also fixed that.
Here is the code where I create my labels. The ratings
is my actual data defined earlier:
// Add blank labels and "Today"
for (i=0; i<ratings.length; i++) {
labels.push("");
}
labels[ratings.length-1] = " ";
var data = {
labels: labels,
datasets: [
{
label: "Progress",
strokeColor: "rgba(255,165,0,1.0)",
pointColor: "white",
pointStrokeColor: "rgba(255,165,0,1.0)",
pointHighlightStroke: "#B87700",
data: ratings
}
]
};
Even if you have actual labels on your graph, you could add spaces to your last label to make it bigger. If you are centering your label, you could add the same amount of space before and after.
Obviously there will be limits where this will or won't work for you, but for my case I added 7 spaces and all looks good now.
Also, my case had an issue on the right side, whereas this question has an issue with the left side. The same fix should work, but putting the space on the first label.
score:4
You can add internal padding to the chart. For instance in my case I had a cut of tooltips on the right.
options: {
responsive: true,
maintainAspectRatio: false,
cutoutPercentage: 60,
legend: {
display: false
},
animation: {
animateRotate: false
},
layout: {
padding: {
right: 40
}
}
}
Source: stackoverflow.com
Related Query
- Chart.js pie tooltip getting cut
- Chart JS data labels getting cut
- Pie chart is not getting rendered in ChartJS
- ChartJS version 3 how to add percentage to pie chart tooltip
- High and low points on chart getting cut off
- ng2-Chart: can we show the tooltip data of pie chart on load?
- ChartJS - Horizontal Stacked Bar Chart Tooltip being cut off by Bottom of Canvas
- How to display Tooltip without hovering pie chart with Chart.JS
- ChartJS tooltip label for pie cart being cut
- getting additional value fields from data source for dx.chartjs doughnut chart
- Getting the HTML code of a chart created by chart.js
- Chartjs pie chart tooltip mode label
- I'm new to node.js, and I'm working on getting a pie chart working
- Chart.js Show labels on Pie chart
- Chartjs random colors for each part of pie chart with data dynamically from database
- Pie Chart Legend - Chart.js
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- How to prevent first/last bars from being cut off in a chart with time scale
- chart.js: Show labels outside pie chart
- How set color family to pie chart in chart.js
- Chart JS custom tooltip option?
- chartjs tooltip is cut off when out of canvas
- chart.js scatter chart - displaying label specific to point in tooltip
- Chart.js line chart is cut off at the top?
- chartjs datalabels change font and color of text displaying inside pie chart
- show label in tooltip but not in x axis for chartjs line chart
- Chart.js doughnut chart tooltip size?
- ChartJS add tooltip to a grouped bar chart
- Chart JS Show HTML in Tooltip
- chart js tooltip how to control the data that show
More Query from same tag
- Vue.js: How to retrieve data from API for vue chart.js
- Chart.js not working - Uncaught RefernceError:
- Height for chart area (not the canvas size)?
- Method inside Activate in Aurelia
- ChartsJS Legend not showing in Angular11
- Creating a diagonal shaded area in chart.js
- How to select and pass array object to data setting of chart.js config?
- Canvas won't appear in html
- how to minimize x axis labels to day hours in chart js
- How to chart detected activities on the hour using Chart.js
- Align doughnut/pie charts vertically in the container
- How to implement chart.js in Angular2
- ng2-charts customize data and whole html content of tooltip displayed when hovering on bar chart
- Adding data to Chart.js line graph from array
- Using chart js options with react-chartjs-2 and typescript
- Chart Js , repeated labels yAxis
- How can I style ChartJS to always be at the bottom of a div?
- Chart.js is not rendered until zoom in in angular 8
- How to do automatic pan with Chart.js
- Passing json_encode to chart.js won't work
- Comparison between d3.js and chart.js (only for charts)
- Skip dates with no values in chart js
- Chart.JS Can not read property '_meta' of Undefined
- Render Javascript in DOMPDF is not working as expected
- Changing fontFamily on ChartJS bar chart
- Add value to the labels on chartnewjs legend
- Remove background on Chartjs v2 fixed tooltips
- How to use excess vertical space in stacked bar chart?
- Chart.js separation lines
- Is there a way to have the tooltips always shown on a pie/doughnut in Chart.js v3?