score:11
Accepted answer
There are multiple ways of solving this.
One way (in your case), you can solve this, is by setting the bottom padding for your chart layout , like so ...
options: {
layout: {
padding: {
bottom: 25 //set that fits the best
}
},
...
}
ᴅᴇᴍᴏ
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept'],
datasets: [{
label: 'Standard Rating',
data: [0.1, 0.02, 3, 4, 5, 6, 7, 8, 9],
backgroundColor: 'rgba(209, 230, 245, 0.5)',
borderColor: 'rgba(56, 163, 236, 1)',
borderWidth: 1
}]
},
options: {
layout: {
padding: {
bottom: 25 //set that fits the best
}
},
responsive: false,
tooltips: {
yAlign: 'top'
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<canvas id="myChart" width="350" height="200"></canvas>
score:2
Try setting the tooltips position property to nearest.
tooltips : {
position: "nearest"
},
...
score:7
You can use external tooltips option. Here's an example from Chart.js tooltips documentation:
options: {
tooltips: {
// Disable the on-canvas tooltip
enabled: false,
custom: function(tooltipModel) {
// Tooltip Element
var tooltipEl = document.getElementById('chartjs-tooltip');
// Create element on first render
if (!tooltipEl) {
tooltipEl = document.createElement('div');
tooltipEl.id = 'chartjs-tooltip';
tooltipEl.innerHTML = '<table></table>';
tooltipEl.style.backgroundColor = "#FFFFFF";
tooltipEl.style.borderColor = "#000000";
tooltipEl.style.borderWidth = "thin";
tooltipEl.style.borderStyle = "solid";
document.body.appendChild(tooltipEl);
}
// Hide if no tooltip
if (tooltipModel.opacity === 0) {
tooltipEl.style.opacity = 0;
return;
}
// Set caret Position
tooltipEl.classList.remove('above', 'below', 'no-transform');
if (tooltipModel.yAlign) {
tooltipEl.classList.add(tooltipModel.yAlign);
} else {
tooltipEl.classList.add('no-transform');
}
function getBody(bodyItem) {
return bodyItem.lines;
}
// Set Text
if (tooltipModel.body) {
var titleLines = tooltipModel.title || [];
var bodyLines = tooltipModel.body.map(getBody);
var innerHtml = '<thead>';
titleLines.forEach(function(title) {
innerHtml += '<tr><th>' + title + '</th></tr>';
});
innerHtml += '</thead><tbody>';
bodyLines.forEach(function(body, i) {
var colors = tooltipModel.labelColors[i];
var style = 'background:' + colors.backgroundColor;
style += '; border-color:' + colors.borderColor;
style += '; border-width: 2px';
var span = '<span style="' + style + '"></span>';
innerHtml += '<tr><td>' + span + body + '</td></tr>';
});
innerHtml += '</tbody>';
var tableRoot = tooltipEl.querySelector('table');
tableRoot.innerHTML = innerHtml;
}
// `this` will be the overall tooltip
var position = this._chart.canvas.getBoundingClientRect();
// Display, position, and set styles for font
tooltipEl.style.opacity = 1;
tooltipEl.style.position = 'absolute';
tooltipEl.style.left = position.left + window.pageXOffset + tooltipModel.caretX + 'px';
tooltipEl.style.top = position.top + window.pageYOffset + tooltipModel.caretY + 'px';
tooltipEl.style.fontFamily = tooltipModel._bodyFontFamily;
tooltipEl.style.fontSize = tooltipModel.bodyFontSize + 'px';
tooltipEl.style.fontStyle = tooltipModel._bodyFontStyle;
tooltipEl.style.padding = tooltipModel.yPadding + 'px ' + tooltipModel.xPadding + 'px';
tooltipEl.style.pointerEvents = 'none';
}
}
}
Source: stackoverflow.com
Related Query
- chartjs tooltip is cut off when out of canvas
- ChartJS - Horizontal Stacked Bar Chart Tooltip being cut off by Bottom of Canvas
- ChartJs canvas showing previous graph when changing Graph types
- ChartJS Line chart cut off at the top and bottom
- How to make ChartJS not cut off tooltips?
- canvas fill text vanishes when hovering over chartjs pie chart
- ChartJS v2 - Keep tooltip open when user click on a point of a multiple lines chart
- Chartjs tooltip out of page
- ChartJS tooltip when having multiple lines on a time graph
- Chart.js - disable tooltip when cursor moves outside the main canvas
- Chartjs tooltip location when enlarged
- ChartJs does not render chart when binding canvas id in Angular
- ChartJs (ver: 2.8.0): Custom tooltip does not hide if clicked (or mouse pointer is moved) outside the chart canvas area
- ChartJS tooltip label for pie cart being cut
- Tooltip is not displayed when using annotation in ChartJs
- Chartjs doc examples are lightning fast but same code is slow when reproducing
- 'require is not defined' error when attempting to use chartjs in javascript code
- Display Chartjs tooltip values outside the canvas - multi line chart
- Control Scaling of Canvas When dragged out of chart limit
- Tooltip vertically off with overlapping data, in ChartJS
- Chartjs Bar Chart showing old data when hovering
- Chartjs Tooltip Line Breaks
- Chart.js pie tooltip getting cut
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- How do I prevent the scale labels from being cut off in chartjs?
- How to disable a tooltip for a specific dataset in ChartJS
- Truncating canvas labels in ChartJS while keeping the full label value in the tooltips
- How to prevent first/last bars from being cut off in a chart with time scale
- How to modify chartjs tooltip so i can add customized strings in tooltips
- Chartjs v2 - format tooltip for multiple data sets (bar and line)
More Query from same tag
- Some bars of the bar graph are disappearing from Chart.js
- real time scrolling based chart with chart.js
- Add custom data scale to Chart.js
- How to add new x axis in chart JS?
- angular-chart add horizontal line
- Chartjs graphs are not respecting height of container
- Chart.js - Is it possible to have two y axis with positive values one above the other?
- Chart.js - displaying multiple line charts using multiple labels
- daily activity chart using PHP MySQL
- Remove left and right padding in Chart.js
- reset the zoom to the initial in chart.js?
- How can i change a numpy.ndarray to point format with curly brackets - Python 3.7
- ChartJS animate only one dataset
- Chart.js data/label scale
- Display ellipsis for null or empty values in the bar chart using Chart.js
- Chart.js Multiple dataset
- Dynamically create Angular-Chart with data binding
- ChartJS add tooltip to a grouped bar chart
- Tooltip backgroundColor depending on chart color ChartJS
- Chart.js dynamic bar width
- Chart.js: Can I change the "OriginalOptions" variable within the chartjs-zoom-plugin?
- Why do literal arrays work, but not coded arrays?
- ChartJS: Uncaught TypeError: Cannot read property 'call' of undefined
- Cannot change anything in chart options
- How to destroy line graph in ChartJS
- React-Chart.js : How do I increase the space between the legends and chart?
- Chart.js - combine data and label into a single object
- Chart Js - Limit points on graph without limiting data
- ChartJs DrawBorder() Configuration not working
- Setting default to 0 in vuechart.js HorizontalBar