使用React将NVD3自定义工具提示注入DOM

时间:2018-04-12 15:34:32

标签: reactjs nvd3.js

我成功使用chart.interactiveLayer.tooltip.contentGenerator挂钩将一个串行组件(使用ReactDOMServer.renderToStaticMarkup)作为NVD3 1.8.6中的自定义工具提示。在Chrome中。

在第291行的NVD3&tooltip.js文件中有这样的评论:

Bonus - If you override contentGenerator and return false, you can use something like Angular, React or Knockout to bind the data for your tooltip directly to the DOM.

我想知道如何做到这一点,因为我无法弄清楚这是怎么可能的。这将是一个更高效的解决方案,并可能解决我在IE11中遇到的问题。

已解决。以下是打字稿中的工作解决方案(当前打字并不包含元素参数):

chart.interactiveLayer.tooltip.contentGenerator(
        (d, element?: Element) => {
          if (element !== undefined) {
            ReactDOM.render(
              <Component data={d} />,
              element
            );
          }
          return '';
        }
      );

0 个答案:

没有答案
相关问题