获取Highcharts宽度

dam*_*ser 5 jquery tooltip width highcharts

我想得到当前的图表宽度,我尝试过这样的事情:

chart.width
Run Code Online (Sandbox Code Playgroud)

$(this).parent().width()
Run Code Online (Sandbox Code Playgroud)

图表是哪里

chart = new Highcharts.Chart({ ... })
Run Code Online (Sandbox Code Playgroud)

但是不起作用......

更多信息

我想在导出按钮的左侧放置一个图像(帮助器)(响应).

目前我有以下代码:

$(document).ready(function() {
     chart = new Highcharts.Chart({
        chart: {
            renderTo: 'area1',
            type: 'bar',
            events: {
                load: drawImages,

            }
         ...}
      })
    })
Run Code Online (Sandbox Code Playgroud)

function drawImages() {
    var chart = this;
    x = chart.plotRight - 50

    chart.renderer.image('/assets/faq.png', x, 0, 20, 20)

    .attr({
        zIndex: 100,
        title: "My title for displaying a tooltip"
    })
    .css({
        cursor: 'pointer'
    })
    .add();   
    };
Run Code Online (Sandbox Code Playgroud)

但图像显示在图表的左侧(使用plotRight).

我知道如何获得图形的div容器的宽度("area1"),但我希望代码更像面向对象(因为我每页至少有5个图形).

Seb*_*han 15

在图表对象中,您可以访问chartWidth参数,该参数保持图表的宽度.

http://jsfiddle.net/7xNQL/1/

//callback
    function(chart){

                console.log(chart.chartWidth);

            }
Run Code Online (Sandbox Code Playgroud)


dam*_*ser 7

最后我找到了一个解决方案,使用方法"container":

$(chart.container).width()
Run Code Online (Sandbox Code Playgroud)

这将返回图表的当前宽度.

  • 在图表事件中,我不得不将其称为`$(this.container).width()`。可能对其他所有人都很明显,但是我是新手;-) (2认同)