score:0
var ctx = document.getElementById("canvas").getContext("2d");
var data = {
labels: [
"Red",
"Green",
"Yellow"
],
datasets: [{
data: [300, 50, 100],
backgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56"
],
hoverBackgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56"
]
}]
};
Chart.pluginService.register({
beforeRender: function(chart) {
if (chart.config.options.showAllTooltips) {
// create an array of tooltips
// we can't use the chart tooltip because there is only one tooltip per chart
chart.pluginTooltips = [];
chart.config.data.datasets.forEach(function(dataset, i) {
chart.getDatasetMeta(i).data.forEach(function(sector, j) {
chart.pluginTooltips.push(new Chart.Tooltip({
_chart: chart.chart,
_chartInstance: chart,
_data: chart.data,
_options: chart.options.tooltips,
_active: [sector]
}, chart));
});
});
// turn off normal tooltips
chart.options.tooltips.enabled = false;
}
},
afterDraw: function(chart, easing) {
if (chart.config.options.showAllTooltips) {
// we don't want the permanent tooltips to animate, so don't do anything till the animation runs atleast once
if (!chart.allTooltipsOnce) {
if (easing !== 1)
return;
chart.allTooltipsOnce = true;
}
// turn on tooltips
chart.options.tooltips.enabled = true;
Chart.helpers.each(chart.pluginTooltips, function(tooltip) {
tooltip.initialize();
tooltip.update();
// we don't actually need this since we are not animating tooltips
tooltip.pivot();
tooltip.transition(easing).draw();
});
chart.options.tooltips.enabled = false;
}
}
})
var myPieChart = new Chart(ctx, {
type: 'pie',
data: data,
options: {
showAllTooltips: true
}
});
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0/dist/Chart.min.js"></script>
<canvas id="canvas"></canvas>
score:6
Not sure if this will help you, but I had a similar issue with stacked bar charts. I wanted to show values at the top of the bars, but I found that if the tooltips were open the values were written over the top of the tooltips, making both unreadable. I decided I wanted to show the values only if the tooltips were not showing (and were not rendered if a tooltip was open).
Turns out I can use the tooltip's opacity setting to determine if the tooltip is showing or not. This is very over-simplified, but this is what I came up with:
options: {
tooltips: {
custom: function( tooltip ) {
if( tooltip.opacity > 0 ) {
console.log( "Tooltip is showing" );
} else {
console.log( "Tooltip is hidden" );
}
return;
}
}
}
Having worked that out, I was then able to save a global variable that I could test elsewhere to see if the tooltip was showing.
Source: stackoverflow.com
Related Query
- How to detect when Tooltip closes in chart.js?
- How to disable Chart JS tooltip when there is no value?
- How to show tooltip only when data available in chart js?
- chart js tooltip how to control the data that show
- ng2-charts customize data and whole html content of tooltip displayed when hovering on bar chart
- Chart.js line chart tooltip shows wrong label when line doesn't start at first label
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- Tooltip flickering when hovered on chart
- ChartJS version 3 how to add percentage to pie chart tooltip
- ChartJS v2 - Keep tooltip open when user click on a point of a multiple lines chart
- How to underline and bold tooltip chart js
- How to sort XY line chart tooltip items based on value and add thousands separators?
- How can I have different values for the chart and the tooltip in chart.js?
- How can I build a double doughnut chart that spins when triggered
- How can I re-distribute values within a charts.js pie chart when a legend item is turned off/on?
- How to detect click on chart js 3.7.1 axis label?
- Chart JS tooltip appears differently when set from script instead of html
- How to clear/destroy Chart.js canvas when the chart is represented as a react JSX element
- How to show tooltip value of all data falling on the same axis in chart js?
- How to customize tooltip on mouse hover of a polar area chart of Angular Charts
- React & Chartjs: How can I best destroy my chart when re-rendering?
- How to get access to Chart instance related to current tooltip callback in Chart.js
- How to show/hide animation when legend clicked chart js
- How to get clicked bar chart tooltip data?
- How to print a chart rendered by code
- How to display Tooltip without hovering pie chart with Chart.JS
- How can I remove the white border from Chart.js pie chart when all legends are hidden?
- chartjs - How to access chart instance in a custom tooltip callback
- How to change the position of the tooltip for the Bar type chart in Chart.Js
- How can I show "No Data" message in Pie Chart when there is no data using VueJS?
More Query from same tag
- Dynamically update the options of a chart in chartjs using Javascript
- Cannot call a function in Javascript - Chart.js
- ChartJs is not working in angular 4 with no errors
- ChartJS AJAX Javascript
- How should data be structured for lineplots with vue/chart.js
- ChartJS zoom/pan onPan event not firing in React useEffect hook
- How to commaize the data values provided to a chart in Chart.JS?
- Uncaught TypeError When Trying to get Canvas
- How To Use Api Data With Vue Chart.js
- time scatter plot w/ chart.js
- How To Match Left and Right Tick Intervals with Chartjs
- how to populate my chartjs piechart dynamically
- increase the label size of a line chart in chart.js
- Chart.js How to get min-max values of X axis?
- Chart.js v2: How to make tooltips always appear on pie chart?
- Chart.js - Getting data from HTML
- Dynamic information in chart.js radar chart
- Chart.js time series showing empty plot
- Chart Js Line chart with fill on click with full information of its legend text
- Chart.js responsive pie chart
- How to display the values inside the pie chart of PrimeNG (chart) using JavaScript or Angular
- ChartJS : chartjs-plugin-datalabels The value is in the wrong place
- Change `font-family` in Angular Chart.js
- react chart js skip zero value month
- How to draw round edges with chart.js for line diagrams
- Chart js cut the title and the legends
- error : "Uncaught TypeError: Cannot read property 'length' of null" Chart.js
- Chart.js not drawing with AngularJS
- Line graph - ChartJS
- How to realtime plotting firebase data to ChartJS