question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I access the vue component instance inside callback of options.tooltips?

See original GitHub issue

First of all, Thank You for this wonderful package 😍 . This package made my day ❤️ .

I’m in a situation where I need to construct the tooltip data using props. So I have used tooltips.callbacks.label option referred from docs.

Inside the label: function(tooltipItem,data){} I need to use props passed from the parent component, but what I’m getting is tooltip instance for this (As per the docs).

Is there any way to get VueComponet instance inside that function? Thanks in Advance 😃

Environment

  • vue.js version: ^2.5.16
  • vue-chart.js version: ^3.4.0
  • npm version: 6.4.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
aperturelesscommented, Mar 8, 2019

¯_(ツ)_/¯

Just like I said:

So put your options in a computed property and use arrow functions and you should be fine.

https://codepen.io/apertureless/pen/BZKBdX

Instead of

label: function(tooltipItem,data){}

use

label: (tooltipItem, data) => {
}
2reactions
aperturelesscommented, Feb 20, 2019

Well, this has nothing to to with either chart.js or vue-chartjs. Thats Javascript basics. this in callbacks always refers to the method that calls the callback. In this case this will refer to the window object / chartjs object and not to the vue compontent prototype.

There are enough resources and tutorials on how to handle this in callbacks.

The easiest way is to use arrow functions or .bind(this). So put your options in a computed property and use arrow functions and you should be fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Reference prop from callback - Stack Overflow
I am trying to reference the vue props inside ...
Read more >
Tooltip | Components - BootstrapVue
A function (callback) that returns a reference to an HTMLElement or SVGElement. For more information on references, see the official Vue documentation. Note:....
Read more >
Tooltip Component - ag-Grid (Vue)
The example below demonstrates how to provide custom tooltips to the grid. Notice the following: The Custom Tooltip Component is supplied by name...
Read more >
Access component vm inside of non-arrow function - Laracasts
I am currently working with VueJS and HighchartsJS and running into a bit of a this issue. Whenever Highcharts provides a callback in...
Read more >
Vue Tooltip | Popover Component - Syncfusion
Automatically adjust display position based on view page without inconsistent. · Customize the content with icons, images, or dynamic AJAX template and much...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found