当存在滚动条时,在自举流体跨度中,Highcharts图形宽度不正确

Eth*_*eal 1 css highcharts twitter-bootstrap

我不确定这是一个bootstrap或highcharts问题,但我似乎无法使我的图表正确调整大小; 当存在滚动条和引导跨度时,初始图表宽度太宽.调整窗口大小似乎永远不会产生太宽的宽度,但有时它们太窄.

从span构造中删除代码似乎在所有情况下都会产生适当的宽度,因此我认为hc和bootstrap之间可能存在一些有害的交互.

我做了一个演示小提琴,但请记住,您的浏览器窗口需要足够短以导致滚动条:

http://jsfiddle.net/xEtherealx/Q5EGX/15/

有没有办法可以通过CSS强制宽度符合?我可以在窗口调整大小上创建一个回调作为一种解决方法,但我宁愿找到一个合适的解决方案.

编辑:根据建议,以下是一种解决方法,可以在一些超时后调用,或者在页面加载后调用一次:

    this.setChartSize = function() {
        chart.setSize( $(chart.container).parent().width(), $(chart.container).parent().height() );
        return false;
    };
Run Code Online (Sandbox Code Playgroud)

HTML:

<div id="content" class="container-fluid">
    <div class="row-fluid">
        <div id="toresize" class="span3" style="background: gray; overflow: auto;">
            <div class="targetpane">
                 <h4 class="text-center">HC Sizing Test</h4>

                <!-- take up space -->
                <div class="well well-small" style="height: 160px;"></div>

                <!-- Chart -->
                <div class="well well-small" style="padding: 5px;">
                    <div id="barchart" style="height: 160px; margin-bottom: 5px;"></div>
                </div>

                <!-- take up space -->
                <div class="well well-small" style="height: 160px;"></div>
            </div>
        </div>

        <!-- span -->
        <div class="span9" style="background: gray;">
            <div class="myBorder">Some content</div>
        </div>
    </div>
</div>
<script src="http://code.highcharts.com/highcharts.js"></script>
Run Code Online (Sandbox Code Playgroud)

CSS:

@import url('http://twitter.github.com/bootstrap/assets/css/bootstrap.css');
.well
{
    background-color: #444;
}

.targetpane
{
    color: #888;
    background-color: #1B1B1B;
    border: 1px solid #888;
    border-radius: 3px;
    padding: 0px 5px 0px 5px;
}

.bodycontainer {
    height: 50px !important;
    white-space: nowrap;
    overflow-x: hidden;
}
Run Code Online (Sandbox Code Playgroud)

JS:

var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'barchart',
        borderWidth: 1
    },
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }]
});

$(window).resize(function () {
    $('#toresize').height($(window).height() - 3);
    console.log($(window).height());
})
$(window).resize();
Run Code Online (Sandbox Code Playgroud)

Paw*_*Fus 5

问题是当页面加载时,Highcharts的容器宽度不同.我认为这是由于渲染时间(花费超过1毫秒),所以可能的解决方案是确保图表在渲染后具有适当的高度和高度:http://jsfiddle.net/Q5EGX/17/(参见控制台评论)

setTimeout(function() {
      chart.setSize($("#barchart").width(), $("#barchart").height());
}, 1);
Run Code Online (Sandbox Code Playgroud)