【问题标题】:highcharts show tooltip on point clickhighcharts 在点击时显示工具提示
【发布时间】:2016-04-22 14:03:59
【问题描述】:

我正在尝试更改我的 highcharts 的行为,以在单击某个点而不是将鼠标悬停在上面时显示有关数据的工具提示,这是我的图表对象代码,

this.chart = new Highcharts.Chart({

        chart : {
            renderTo : $container[0],
            type : chartType,
            events : {
                load: function() {
                    this.myTooltip = new Highcharts.Tooltip(this, this.options.tooltip);
                    console.log(this.myTooltip);
                }
            }
        },
        title: {
            enabled : false,
            useHTML: true,
            text: ''
        },
        legend : {
            enabled : false
        },
        xAxis: {
            categories: self.categories,
            labels : {
                rotation : 90,
                formatter: function(){
                    return '<a href="" class="axisLabel" data-name="'+ this.value +'">' + this.value + '</a>';
                },
                useHTML: true,
                padding: '10px',
                y: 30,
                x: -5,
                align:'left'
            }
        },
        yAxis: {
            allowDecimals: false,
            opposite:false
        },
        tooltip: {
            enabled: false,
            useHTML : true,
            backgroundColor: "rgba(255,255,255,1)",
            formatter : function() {
                if(self.graphView != "turn") {
                    var tooltip = self.showClientProjects(this.x, self.organisation_filter, this.y, self.graphView);
                    self.pointIndex = this.point.index;
                    return tooltip.innerHTML;
                } else {
                    console.log(this.x);
                    var tooltip = self.showClientProjects(this.x, null, null, self.graphView);
                    self.pointIndex = this.point.index;
                    return tooltip.innerHTML;
                }
            }
        },
        plotOptions: {
            column: {
                maxPointWidth: 5,
                pointPadding: 0.2,
                //borderWidth:1
            },
            series: {
                stickyTracking: false,
                events: {
                    click: function(evt){
                        this.chart.myTooltip.refresh(evt.point, evt)
                    },
                    mouseOut: function() {
                        this.chart.myTooltip.hide();
                    }
                }
            }
        },
        series: [{
            data : data,
            dataLabels : {
                crop : false
            }
        }]

    });

单击一个点会返回此错误,

highcharts.src.js:1319 Uncaught TypeError: Cannot read property 'call' of null 这行代码来自 highcharts 库,

 // If the event handler return false, prevent the default handler from executing
 if (fn.call(el, eventArguments) === false) {
     eventArguments.preventDefault();
 }

然而,它在我敲响的快速小提琴上效果很好,

http://jsfiddle.net/d1gL4cjx/1/

【问题讨论】:

  • 你的小提琴坏了:Uncaught Error: Highcharts error #13: www.highcharts.com/errors/13
  • 您提供的小提琴与您提供的代码不匹配。
  • 如果您向 Highcharts 提供有关渲染 div 的正确信息,那么图表似乎工作正常 - jsfiddle.net/gqxzv8bL/1。此外,不要为配置对象设置两个相同的属性以避免意外行为 - 您使用加载事件设置图表两次。 (在此评论中提供的小提琴中删除了问题。)

标签: javascript jquery highcharts


【解决方案1】:

这里是更新(固定)小提琴的链接: http://jsfiddle.net/d1gL4cjx/2/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多