javascript - Adjusting spacing in a Highcharts chart dynamically -


here's problem:

i have multiple charts under various tabs. after loading chart, add svg text , rect display additional legend after plot. each chart might have different legend can vary in length, space required may vary.

i use spacingbottom value allow space legend displayed. set value manually before chart loaded (as in example below), can lots of work if text in legends changed.

what can set spacingbottom value required number based on height of legend container?

the example can seen here:

http://jsfiddle.net/anlsz/1/

$(function () {     var mylegends = [         '*: lorem ipsum dolor sit amet, consectetur adipiscing elit.',     '<strong>np</strong>: pellentesque in sapien diam, ac tristique dolor. curabitur sit amet est nunc, eget egestas neque.',     '<strong>np</strong>: pellentesque sollicitudin ultrices tristique. aenean pharetra nulla eget turpis tincidunt vulputate. sed pulvinar nisi et ante iaculis vulputate.',     '<strong>*</strong> donec elit enim, fermentum sit amet varius a, feugiat @ nunc. aliquam ac mi eu nunc dapibus interdum. ',     '<strong>**</strong> proin rutrum tincidunt sollicitudin. vestibulum sit amet dui odio. suspendisse potenti. integer accumsan iaculis est ut tempor. ',  ];  function drawlegend(chart, legends) {     //si il y des légendes, les ajouter     var selectedlegends = '';     var myboxheight = 12;     texty = chart.chartheight - chart.options.chart.spacingbottom + 25;     if (legends.length != 0) {          var counter = 0;         (counter = 0; counter < legends.length; counter++) {             legendnum = legends[counter];             selectedlegends += mylegends[legendnum] + '<br/>';         }         selectedlegends += '<span style="color: #eeeeee">.</span><br/>';      }          var text = chart.renderer.text(selectedlegends, 15, texty).attr({             zindex: 5         }).css({             color: '#222222',             fontsize: '9.5px',             lineheight: '12px',             width: (math.min(chart.chartwidth - 30,650)) + 'px'         }).attr({                 'xml:space': 'preserve'             }).add();         var box = text.getbbox();          var legendcontainer = chart.renderer.rect(box.x - 5, box.y - 5, box.width + 10, box.height + 10, 5)             .attr({             fill: '#eeeeee',             stroke: '#b8b8b8',             'stroke-width': 1,             zindex: 4         })             .add();         console.log (legendcontainer.height);         //need this:         //chart.options.chart.spacingbottom = legendcontainer.height + 10;  }      $('#container').highcharts({         chart: {             type: 'line',             borderwidth: 1,             spacingbottom: 100,             plotborderwidth: 1,             events: {                         load: function () {                             drawlegend(this, [1,2,3]);                         }                     }         },         xaxis: {             categories: ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']         },         yaxis: {            },         tooltip: {             formatter: function() {                 return '<b>'+ this.series.name +'</b><br/>'+                     this.x +': '+ this.y;             }         },         plotoptions: {         },         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]                 }]     }); }); 

maybe there better way manage problem outside of spacingbottom option?


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -