简体   繁体   English

使用 react 在 echarts 中自定义工具提示设计

[英]customising tooltip design in echarts with react

I'm working on a chart using echarts library with antd and react and I have to follow a specific tooltip design as below :我正在使用带有 antd 和 react 的 echarts 库处理图表,我必须遵循特定的工具提示设计,如下所示:

预期的工具提示

what I could do is :我能做的是:

实际工具提示

tooltip implementation :工具提示实现:

 const chartOptions = {


    tooltip: {
        trigger: 'item',
        responsive: true,
        position: 'top',
        formatter: '{c}',
        backgroundColor: '#fafcfe',
        borderColor: '#c8e2f7',
        borderWidth: '0.8',
        textStyle: {
            color: '#5d6f80'
        }
    },
    xAxis: {
        data: xdata,
    },

    yAxis: {
        type: 'value',
        position: 'right',
    },
    series: [{
        data: data1,
        type: 'line',
        name: 'data1',
    },
    {
        data: data2,
        type: 'line',
        name: 'data2',
    } ] 
} 

is there any way to add the down arrow and the link ( baby blue line between the tooltip and symbol)有什么方法可以添加向下箭头和链接(工具提示和符号之间的淡蓝色线)

css solution is acceptable but I'm beginner in css and frontend development in general css 解决方案是可以接受的,但我一般来说是 css 和前端开发的初学者

any suggestion would be helpful, thank you任何建议都会有所帮助,谢谢

To add that vertical axis line, you can simply change to trigger: 'axis' .要添加该垂直轴线,您只需更改为trigger: 'axis' Beware that position: 'top' does not work with this option, so you would have to change it to something like this:请注意position: 'top'不适用于此选项,因此您必须将其更改为如下所示:

position: function (point) {
    return [point[0], '20%'];
    // if u wanna center it to the line, then u could do something like
    // [point[0] - width_of_tooltip / 2, '20%']
}, ...

Regarding the down arrow, I see two options:关于向下箭头,我看到两个选项:

Change the formatter option to a function:将格式化程序选项更改为函数:

formatter: function (params) {
        return `<div class="tooltip">${params[0]}</div>`;
    }, ...

and then you can create the arrow with css, assigned to that tooltip class (see the example under Tooltip Arrows here: https://www.w3schools.com/css/css_tooltip.asp ).然后您可以使用 css 创建箭头,分配给该tooltip类(请参阅此处工具提示箭头下的示例: https : //www.w3schools.com/css/css_tooltip.asp )。

Other option, would be to manually add a background image of a tooltip arrow and assign it through the extraCssText option, like this:其他选项是手动添加工具提示箭头的背景图像并通过extraCssText选项分配它,如下所示:

tooltip: {
    trigger: 'axis',
    extraCssText: "background-image: url(https://f0.pngfuel.com/png/287/216/white-box-illustration-png-clip-art.png);background-size:cover;min-height:100px;",
    ...
}

there you can add more css options to make it look like you want (I just chose a random bubble text box).在那里您可以添加更多 css 选项以使其看起来像您想要的(我只是选择了一个随机气泡文本框)。 I'd personally like the first option better.我个人更喜欢第一个选项。 Good luck!祝你好运!

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

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