HighCharts full width issue

2019-03-26 08:09发布

Im trying to make my rendered chart fill 100% of the parent div with no success. Is there any way I can remove the gap on the left and right sides?

http://jsfiddle.net/sKV9d/

var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'chart',
        margin: 0,
        width: 300,
        height: 200,
        defaultSeriesType: 'areaspline'
    },    

    series: [{
        data: [33,4,15,6,7,8, 73,2, 33,4,25],    

        marker: {
            enabled: false
        }
    }]
});

7条回答
Ridiculous、
2楼-- · 2019-03-26 08:20

I solved it by

window.dispatchEvent(new Event('resize'));

UPD:

  1. remove width and height attributes.
  2. add into .css the following code in order to adjust chart block to 100% of #container:

chart { width: 100%; height: 100%; }

2a. another way is - in case if not possible to define container size during "design" time you can reflow chart after chart load (i.e. call chart.reflow(); ):

chart: {

    events: {
        load: function(event) {
        **event.target.reflow();**
      }
    }
},

See example http://jsfiddle.net/yfjLce3o/

查看更多
迷人小祖宗
3楼-- · 2019-03-26 08:21

use updateChart function and call chart.reflow() inside that function

scope.updatechart = function(){
     scope.chart.reflow();
}

call updatechart method every 30 seconds using any refresh mechanism

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-03-26 08:24

The issue is because of jquery UI. after rendering your chart call this code to reflow the chart. This fixed my problem

chart.reflow();
查看更多
萌系小妹纸
5楼-- · 2019-03-26 08:30

If you remove the options width: 300, height: 200 like this:

    var chart = new Highcharts.Chart({
chart: {
    renderTo: 'chart',
    margin: 0,
    defaultSeriesType: 'areaspline'
},    

...

it will fill automatically the container.

查看更多
Evening l夕情丶
6楼-- · 2019-03-26 08:36

Set minPadding and maxPadding to 0, see: http://jsfiddle.net/sKV9d/3/

查看更多
疯言疯语
7楼-- · 2019-03-26 08:45

Try this :

var height= $("#container").height();
var width= $("#container").width();

var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'chart',
        margin: 0,
        width: width,
        height: height,
        defaultSeriesType: 'areaspline'
    },    

    series: [{
        data: [33,4,15,6,7,8, 73,2, 33,4,25],    

        marker: {
            enabled: false
        }
    }]
});
查看更多
登录 后发表回答