-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to hide the tooltip of a specific dataset #1889
Comments
At the moment, there is no way to do this. I'd be happy to look over a PR adding this. |
thanks @etimberg! |
@kerron if you want to try modifying the library yourself, I'd suggest looking at I'd be happy to look at a PR adding this functionality |
Update: see this answer: http://stackoverflow.com/a/37297802/1827284** I modify the library to do this: First I add Chart.controllers.bar = Chart.DatasetController.extend({
updateElement: function updateElement(rectangle, index, reset, numBars) {
...
helpers.extend(rectangle, {
...
// Desired view properties
_model: {
...
// Tooltip
label: this.chart.data.labels[index],
datasetLabel: this.getDataset().label,
tooltip: this.getDataset().tooltip, // Line added !!
... Then I modify Core.Tooltip.draw to add Chart.Tooltip = Chart.Element.extend({
...
draw: function draw() {
...
// Check if show dataset tooltip
var showTooltip = (this._active[0] && this._active[0]._model.tooltip !== false);
if (this._options.tooltips.enabled && showTooltip) { Finally I define this option in my datasets: this.myChart = new Chart(this.ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [
{ type: 'line', data: data3 },
{ type: 'bar', data: data1, backgroundColor: "#3EAFD5" , tooltip: false},
{ type: 'bar', data: data2, backgroundColor: "#D24B47", tooltip: false}
]
}
} |
Hi, I'm on v2.5, I have a multi datasets in a line chart, and I just wanna show tooltip for one dataset, your solution doesn't work for me, here's my code
Any idea? |
@qiluo I suggest you using the option |
@qiluo try:
|
hi guys, I successfully hide the tooltip now with above method, thanks |
I am using the above approach to filter points from the tooltip, but I want to not show the tooltip at all when all points have been filtered out. Right now i'm getting an empty tooltip. IE: I have a line chart with multiple datasets and a feature to highlight one line by clicking on it and when a line is highlighted only tooltips for that dataset are visible. |
Hey guys, tooltips: {
custom: function(tooltipModel) {
// EXTENSION: filter is not enough! Hide tooltip frame
if (!tooltipModel.body || tooltipModel.body.length < 1) {
tooltipModel.caretSize = 0;
tooltipModel.xPadding = 0;
tooltipModel.yPadding = 0;
tooltipModel.cornerRadius = 0;
tooltipModel.width = 0;
tooltipModel.height = 0;
}
},
// Hide tooltip body
filter: function(tooltipItem, data) {
return !data.datasets[tooltipItem.datasetIndex].tooltipHidden; // custom added prop to dataset
} Have a look at my sample https://jsfiddle.net/Lq3aptph/ |
The solution of @thomasjoscht works perfectly! Only thing I have to add is that you need to add This is only the case when you want to have that dataset visible ofcourse, in the fiddle the dataset is completely opaque, making this unnecessary. |
@andrei-kondakov you saved my life. Thank you! |
@Evertvdw Where did you add |
You can search the docs for |
I thought I'd contribute some. I have 3 datasets and I created a 4th one as a trendline, but I didn't want to show that in the legend or in the basic tooltip. Using this code, I was able to get what I wanted. Legend and the default tooltip only show the first 3 datasets, but the line is still there on the line chart.
|
Just in case someone comes across this like me and has some questions / it's still not working / not a perfect solution, I have found the perfect solution for me. I will be more verbose to reduce questions. "dependencies": {
App.vue relevant snippet:
Relevant to the question of filtering values within datasets:
And this code for me was within the BarChart.vue component:
'./../helpers.js'
|
|
Is there a way I can hide the tooltip of a specific datasets in v2-beta? I can hide the data using the callback functions, but this still leaves a tooltip, albeit empty.
Is there a way to hide its entirety?
The text was updated successfully, but these errors were encountered: