D3.tip is not a function

I am trying to add d3.tip to my d3 infographic. According to the d3.tip documentation, I installed d3.tip with Bower. When the installation is complete, the following is displayed on my terminal screens:

Terminal screen

I assume it was successfully installed.

But when I added d3.tip to my codes, console.log continues to show "Barchart2.html: 121 Uncaught TypeError: d3.tip is not a function."

Here is my code:

Part d3.tip of my script code

Can someone tell me how to solve the problem please?

+5
source share
1 answer

You need to import d3-tip as imported d3 js. I assume you installed d3-tip correctly.

import * as d3 from 'd3'; import d3Tip from "d3-tip"; 

Then you can use it as below:

 var tip = d3Tip().attr('class', 'd3-tip').offset([-12,0]) .html(function(d) { /* your code goes here */ }); 

This should fix your problem.

+1
source

All Articles