简体   繁体   中英

How to add tooltip in Echarts to Radar indicator

I am trying to add tooltips to the Radar indicator elements. So far I tried tooltip:{show:true, trigger: "item", value:"tooltipText"} in the indicator element but no luck:(, can be seen below in the code. For example if I hover on top of "销售(Sales)" it should show a tooltip with "tooltipText".

Running code example: https://echarts.apache.org/examples/en/editor.html?c=radar

option = {
    title: {
        text: '基础雷达图'
    },
    legend: {
        data: ['预算分配(Allocated Budget)', '实际开销(Actual Spending)']
    },
    tooltip: {
        trigger: 'item'
    },
    radar: {
        // shape: 'circle',
        indicator: [
            { name: '销售(Sales)', max: 6500, tooltip:{show:true, trigger: "item", value:"tooltipText"}},
            { name: '管理(Administration)', max: 16000, tooltip:{show:true, trigger: "item", value:"tooltipText"}},
            { name: '信息技术(Information Technology)', max: 30000, tooltip:{show:true, trigger: "item", value:"tooltipText"}}
        ]
    },
    series: [{
        name: '预算 vs 开销(Budget vs spending)',
        type: 'radar',
        data: [
            {
                value: [4200, 3000, 20000, 35000, 50000, 18000],
                name: '预算分配(Allocated Budget)'
            },
            {
                value: [5000, 14000, 28000, 26000, 42000, 21000],
                name: '实际开销(Actual Spending)'
            }
        ]
    }]
};

Just add "tooltip: {}" inside option. Like this, you can change the tooltip inside the series option, the same way you were doing before.

The code would look like this:

option = {
title: {
    text: '基础雷达图'
},
legend: {
    data: ['预算分配(Allocated Budget)', '实际开销(Actual Spending)']
},
radar: {
    // shape: 'circle',
    indicator: [
        { name: '销售(Sales)', max: 6500},
        { name: '管理(Administration)', max: 16000},
        { name: '信息技术(Information Technology)', max: 30000},
        { name: '客服(Customer Support)', max: 38000},
        { name: '研发(Development)', max: 52000},
        { name: '市场(Marketing)', max: 25000}
    ]
},
tooltip: {},
series: [{
    name: '预算 vs 开销(Budget vs spending)',
    type: 'radar',
    data: [
        {
            value: [4200, 3000, 20000, 35000, 50000, 18000],
            name: '预算分配(Allocated Budget)'
        },
        {
            value: [5000, 14000, 28000, 26000, 42000, 21000],
            name: '实际开销(Actual Spending)'
        }
    ],
    tooltip:{
       // do something here if you want
    }
}]

};

Try removing the tooltip div from canvas and append it to the body worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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