javascript - 我可以在悬停时使用 highcharts 列堆叠而不突出显示整个系列吗

标签 javascript jquery html css highcharts

正如你在这里看到的jsfiddle . 如果我使用 highcharts columns使用 列:{stacking: 'normal'}

当您将鼠标悬停在它上面时,它会突出显示具有相同名称的整个系列。

有什么方法可以只突出显示悬停的元素并且不会以任何方式影响系列中的其他元素? 我还想保留悬停标签。

Highcharts.chart('container', {
    chart: {
        type: 'column'
    },
    title: {
        text: 'Stacked column chart'
    },
    xAxis: {
        categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
    },
    yAxis: {
        min: 0,
        title: {
            text: 'Total fruit consumption'
        },
        stackLabels: {
            enabled: true,
            style: {
                fontWeight: 'bold',
                color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
            }
        }
    },
    legend: {
        align: 'right',
        x: -30,
        verticalAlign: 'top',
        y: 25,
        floating: true,
        backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
        borderColor: '#CCC',
        borderWidth: 1,
        shadow: false
    },
    tooltip: {
        headerFormat: '<b>{point.x}</b><br/>',
        pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
    },
    plotOptions: {
        column: {
            stacking: 'normal',
            dataLabels: {
                enabled: true,
                color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
            }
        }
    },
    series: [{
        name: 'John',
        data: [5, 3, 4, 7, 2]
    }, {
        name: 'Jane',
        data: [2, 2, 3, 2, 1]
    }, {
        name: 'Joe',
        data: [3, 4, 4, 2, 5]
    }]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

最佳答案

您可以禁用inactive 效果并使用hover 状态:

plotOptions: {
    ...,
    column: {
        stacking: 'normal',
        states: {
            inactive: {
                enabled: false
            },
            hover: {
                color: 'blue'
            }
        }
    }
}

现场演示: https://jsfiddle.net/BlackLabel/Lg796ha3/

API 引用: https://api.highcharts.com/highcharts/series.column.states.hover.color

关于javascript - 我可以在悬停时使用 highcharts 列堆叠而不突出显示整个系列吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56164588/

相关文章:

html - 为什么 Chrome 没有正确考虑边距?

php - 在相同列名的表中循环获取图像

javascript - css3 根据光标旋转

javascript - Chrome 扩展程序多个端口出现“断开连接的端口”错误

javascript - 在不可见的 reCaptcha 回调中传递变量

jquery - 如何使用 XMLHttpRequest 将数组发送到服务器

html - jquery 在列表中查找下一个类

Javascript - 无法调整帧率 - requestanimationframe

javascript - 在aspx页面中打开 Crystal 报表时出错

javascript - 突出显示最小/最大值表jquery