javascript - Optimise Tick Positions To Minimise Wasted Space At Top Of Chart -


if run snippet below, notice in first chart, there lot of space wasted @ top of chart. same chart @ different element height makes better use of space.

how can highcharts optimise tickpositions reduce wasted space?

i've tried tweak following highcharts properties:

  • ceiling
  • floor
  • min
  • max

to no avail.

as sidenote, issue started affecting on upgrading v3 v4 (latest)

var model1 = {    "chart": {},    "xaxis": {      "categories": ["2033", "2034", "2035", "2036", "2037", "2038", "2039", "2040", "2041", "2042", "2043", "2044", "2045", "2046", "2047"]    },    "yaxis": [{}, {      "opposite": true,    }],    "series": [{      "data": [0, 0, 0, 0.210042, 0.310498, 0.328766, 0.328766, 0.328766, 0.328766, 0.328766, 0.328766, 0.328766, 0.328766, 0.305934, 0],      "yaxis": 0    }, {      "data": [0, 0, 0, 9.652964, 13.575342, 14.328766, 14.328766, 14.328766, 14.328766, 14.328766, 14.328766, 14.328766, 14.123286, 12.757988, 0],      "yaxis": 1    }],  };      $(function() {    $('#container1').highcharts(model1);    $('#container2').highcharts(model1);  });    //function increaseheight(){  //$('#container1').height(400);  //console.log("now resize window see chart change");  //}
#container1 {    height: 300px;  }  #container2 {    height: 400px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <script src="https://code.highcharts.com/highcharts.js"></script>    <!-- button onclick="increaseheight()">resize chart 1</button -->  <div id="container1"></div>  <div id="container2"></div>

the reason you're having such trouble particular chart due how highcharts handles dual axes. can tricky work with, , attributes work, such ceiling, min, max, etc. don't work single axis charts.

i posted answer few weeks similar situation , applied few of ideas code snippet (see below).

var model1 = {    "chart": {},    "xaxis": {      "categories": ["2033", "2034", "2035", "2036", "2037", "2038", "2039", "2040", "2041", "2042", "2043", "2044", "2045", "2046", "2047"]    },    "yaxis": [{      "startontick": false,       "endontick": false,       "maxpadding": 0,       "minpadding": 0    }, {      "opposite": true,      "startontick": false,       "endontick": false,       "maxpadding": 0,       "minpadding": 0    }],    "series": [{      "data": [0, 0, 0, 0.210042, 0.310498, 0.328766, 0.328766, 0.328766, 0.328766, 0.328766, 0.328766, 0.328766, 0.328766, 0.305934, 0],      "yaxis": 0    }, {      "data": [0, 0, 0, 9.652964, 13.575342, 14.328766, 14.328766, 14.328766, 14.328766, 14.328766, 14.328766, 14.328766, 14.123286, 12.757988, 0],      "yaxis": 1    }],  };      $(function() {    $('#container1').highcharts(model1);    $('#container2').highcharts(model1);  });    //function increaseheight(){  //$('#container1').height(400);  //console.log("now resize window see chart change");  //}
#container1 {    height: 300px;  }  #container2 {    height: 400px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <script src="https://code.highcharts.com/highcharts.js"></script>    <!-- button onclick="increaseheight()">resize chart 1</button -->  <div id="container1"></div>  <div id="container2"></div>

as can see, "wasted space" reported gone. note, however, relative position of both series differ between different container heights. due how highcharts calculating intervals on each individual axis , plotting them against 1 another.

in other answer, suggested alignticks: false chart attribute, gets bit messy example. also, setting explicit tickinterval first (lighter-colored) series results in same odd offset of gridlines.

so long don't have objection disparity between series positions, should useful you.


Comments