javascript - 如何定位 Highcharts 路径?

标签 javascript jquery html css highcharts

我在图表上绘制路径,我需要在将鼠标悬停在页面上的另一个元素上时更改它们的颜色 - 页面右侧 div 上的数据点列表。

这是我的代码:

chart = new Highcharts.Chart({
    chart: {
        renderTo: 'graph',
        type: 'area',
        backgroundColor: 'transparent',
        height: 470
    },
    plotOptions: {
        area: {
            enableMouseTracking: false,
            showInLegend: false,
            stacking: 'percent',
            lineWidth: 0,
            marker: {
                fillColor: 'transparent',
                states: {
                    hover: {
                        lineColor: 'transparent'
                    }
                }
            }
        }
    },
    series:
        [
            {
                name: 'over',
                color: 'none',
                data: overData
            },
            {
                id: 's1',
                name: 'Series 1',
                data: data,
                showInLegend: true,
                zoneAxis: 'x',
                zones: zones
            },
            {
                name: 'under',
                color: 'none',
                data: underData
            }
        ],
    xAxis: {
        plotLines: plotLines,
        gridLineColor: 'transparent',
        lineColor: 'transparent',
        labels: {
            enabled: false
        }
    },
    yAxis: {
        title: {
            text: ''
        },
        gridLineColor: 'transparent',
        lineColor: 'transparent',
        labels: {
            enabled: false
        }
        //,min: -25
    },
    legend: {
        enabled: false
    },
    title: {
        text: ''
    },
    credits: {
        enabled: false
    },
    tooltip: {
        enabled: false
    }},function(chart){
        dataForChart.forEach(function(entry) {
            chart.renderer.path(['M', ((entry.score*475)/100), 45, 'V',475])
                .attr({
                    'id' :'line_'+entry.id,
                    'stroke-width': 2,
                    stroke: 'white',
                    zIndex:1000
                })
                .add();
        });
});

有问题的代码是这样的:

chart.renderer.path(['M', ((entry.score*475)/100), 45, 'V',475])
    .attr({
        'id' :'line_'+entry.id,
        'stroke-width': 2,
        stroke: 'white',
        zIndex:1000
    })
    .add();

现在我想做的就是在悬停时更改该路径的颜色。如您所见,我确实为每一行分配了一个 id。

我在前端有一列,当用户将鼠标悬停在点的名称上时(在本例中它是捐助者名称,例如美国国际开发署),当发生这种情况时,我想触发悬停状态(最好是之前在我粘贴的第二个代码块)并更改线条颜色。

我怎样才能做到这一点?

1) 如何向该路径添加悬停样式? 2) 当我将鼠标悬停在捐赠者列表中的名称上时,如何触发特定行的悬停状态?

最佳答案

您可以在呈现的对象上添加 .on() 事件。

chart.renderer.path(['M', 0, 0, 'L', 100, 100])
    .attr({
        'stroke-width': 10,
        stroke: 'red'
    })
    .on('mouseover',function(){
      $(this).attr({
        'stroke': 'yellow'
      })
    })
    .on('mouseout',function(){
      $(this).attr({
        'stroke': 'red'
      })
    })
    .add();

示例:http://jsfiddle.net/6g5hfycw/

关于javascript - 如何定位 Highcharts 路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35383190/

相关文章:

jquery - 使变量可用于其他回调

html - 320 像素及以下的媒体查询

javascript - 替换 jquery 中的文本区域

javascript - IE9 似乎无法识别 $.ajax 的 'complete' 事件

javascript - 蒂佩卡诺 Mapbox GL JS

javascript - jquery 如何检查函数是否被触发

html - 固定在屏幕左侧的侧边栏和带有边距 : 0 auto 的中间内容

html - HR : margin-top won't work. 为什么?

javascript - jQuery 元素选择器

javascript - 如何将不透明度应用于非事件 slider 元素?