简体   繁体   English

如何将自定义工具提示添加到 nivo 图表?

[英]How to add custom tooltip to nivo chart?

I'm doing a stream chart with Nivo (nivo(.dot)rocks)) in react.js.我正在 react.js 中使用 Nivo (nivo(.dot)rocks)) 制作 stream 图表。 How to customize the tooltip?如何自定义工具提示? The documentation doesn't talk about this point.文档没有谈到这一点。

in nivo Line chart type case that works for me:在适用于我的 nivo 折线图类型案例中:

 <ResponsiveLine
  data={data}
  tooltip={point => {
    return <div>{point}</div>;
  }}
/>

Maybe you can kick start by something like this也许你可以从这样的事情开始

<ResponsiveLine
    data={data}
    tooltip={({ point }) => {
        return (
            <div
                style={{
                    background: 'white',
                    padding: '9px 12px',
                    border: '1px solid #ccc',
                }}
            >
                <div>x: {point.x}</div>
                <div>y: {point.y}</div>
            </div>
        )
    }} 
/>

I hope this helps someone, because for my package version (0.79.1), tooltip didn't do anything at all.我希望这对某人有所帮助,因为对于我的 package 版本(0.79.1), tooltip根本没有做任何事情。 I found that there's a prop called sliceTooltip that seems to function the same way.我发现有一个名为sliceTooltip的道具,在 function 中似乎也是如此。 I have no idea what the difference is supposed to be, but it's the only one that allowed me to write a custom tooltip component for ResponsiveLine.我不知道应该有什么区别,但它是唯一允许我为 ResponsiveLine 编写自定义工具提示组件的区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM