highcharts - Text Ellipsis in bubble chart -


i'm using bubble chart highcharts, label text inside of bubbles dynamic , can bigger bubble itself,

i wonder if there's way make text ellipsis according size of bubble contain it?

  containeroptions = {         chart: {             type: 'bubble',             renderto: $(container)[0],             events: {                 drilldown: function (e) {                     if (!e.seriesoptions) {                          var chart = this,                             drilldowns = {                                 'animals': {                                     name: 'animals',                                     data: [                                         {name: 'dogs', y:2, x:10, z: 7, drilldown: true},                                         {name: 'cats', y:4, x:12, z: 7}                                     ]                                 },                                 'dogs': {                                     name:"dogs",                                     data: [                                         {name: 'pitbull', y:3.7, x:7.6, z: 5, drilldown: false},                                         {name: 'german shepherd', y:6.7, x:6.9, z: 5, drilldown: false}                                     ]                                 }                             },                             series = drilldowns[e.point.name];                         chart.showloading('loading..');                         settimeout(function () {                             chart.hideloading();                             chart.addseriesasdrilldown(e.point, series);                         }, 1000);                      }                 }             }         },         plotoptions: {             series: {                 borderwidth: 0,                 datalabels: {                     enabled: true,                     style: { color: 'red' },                     format: '{point.name}'                  }             }         },         series: [{             name: 'things',             colorbypoint: true,             data: [{                 name: 'animals',                 y: 5,                 x: 1,                 z: 9,                 drilldown: true             }, {                 name: 'fruits',                 y: 2,                 x: 9,                 z: 9,                 drilldown: false             }             ]         }],          drilldown: {             series: [],             drillupbutton: {                 relativeto: 'spacingbox',                 position: {                     y: 0,                     x: 0                 }             }         }      } } 

you can loop through data labels on load/redraw event , add/remove ellipsis according bubble's width , text's width.

function applyellipsis() {   var series = this.series[0];   var options = series.options.datalabels;    series.points.foreach(p => {     var r = p.marker.radius;     var label = p.datalabel;     var text = label.text.textstr;     var bbox = label.getbbox(true);      while (bbox.width > 2 * r && text.length !== 1) {       text = text.slice(0, -1);       p.datalabel.attr({         text: text + '\u2026'       });       bbox = label.getbbox(true);     }      p.datalabel.align({       width: bbox.width,       height: bbox.height,       align: options.align,       verticalalign: options.verticalalign     }, null, p.dlbox);    }); } 

attach function on load/redraw

highcharts.chart('container', {   chart: {     type: 'bubble',     events: {       load: applyellipsis,       redraw: applyellipsis     }   }, 

example: http://jsfiddle.net/12d997o4/


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -