0

我的 highcharts 图表中有一个按钮,它使用以下代码:

exporting: {
    buttons: {
        backButton: {
            _titleKey: 'backTitle',
            enabled: theChart.buttonOn,
            x: 0,
            y: 300,
            onclick: function () {
                $(this).parents(".chart").data('chart', $(this).parents(".chart").data('mainChart'));
                $(this).parents(".chart").trigger('redoChart');
            },
            text: 'Click to return to full graph',
            width:200,
            theme: {
                'stroke-width': 1,
                stroke: 'black',
                fill: '#cccccc',
                states: {
                    hover: {
                        'stroke-width': 1,
                        stroke: 'black',
                        fill: '#cccccc'
                    },
                    select: {
                        'stroke-width': 1,
                        stroke: 'black',
                        fill: '#cccccc'
                    }
                }
            }
        }
    }
}

当我单击此按钮时,没有任何反应。我已经确定这是因为$(this).parents(".chart")没有正确识别我的图表的容器 div(它确实具有“图表”类)。如果我替换$(this).parents(".chart")$("#thechart"),一切都很好。

4

1 回答 1

1

Use:

$(this.container).parents('.chart').hide();

In the button handler this is a highcharts object. this.container is the highcharts created div within your div. So, to hide the whole thing, you're looking up to the parent that you added a chart class to.

于 2013-10-08T15:16:28.857 回答