简体   繁体   English

悬停时的高图更改dataLabel的字体大小

[英]HighCharts on hover change dataLabel's font size

I have a pie highchart and what i want is to change dataLabels font size when i hover over the specific part of the pie. 我有一个饼图图表,当我将鼠标悬停在饼图的特定部分上时,我想更改dataLabels字体大小。

I found that the hover event is established like this: 我发现悬停事件是这样建立的:

plotOptions: {

            series: {
                shadow: {
                color: '#000',
                offsetX : 5,
                offsetY : 5,
                opacity : 0.5
                },
                events: {
                    mouseOver: function(event) {

                    },
                    mouseOut: function(event) {

                    }
                }

            }

but i dont know how to access dataLabel from inside the mouseOver/Out. 但我不知道如何从mouseOver / Out内部访问dataLabel。

You can reach the dataLabel via this.dataLabel within the point events for the series : 您可以在seriespoint事件中通过this.dataLabel到达dataLabel

series: {
    point: {
        events: {
            mouseOver: function (e) {
                this.dataLabel.css({
                    fontSize: "30px",
                });
            },
            mouseOut: function (e) {
                this.dataLabel.css({
                    fontSize: "12px",
                });
            }
        }
    }
}

Demo 演示

Is the dataLabel you are referring to in HTML? 您使用HTML引用的dataLabel是吗? If you want to access dataLabel you can do this in JavaScript like this (assuming the HTML element is an id): 如果要访问dataLabel,可以在JavaScript中执行以下操作(假设HTML元素是一个id):

document.getElementById("dataLabel").setAttribute("style", "font-size: 20px");

This would set dataLabel's font size to 20px. 这会将dataLabel的字体大小设置为20px。 You can put this inside the mouse event function you desire. 您可以将其放入所需的鼠标事件函数中。

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

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