javascript - realign Labels only to single Chart or type chart on highcharts -
i followed tutorial: http://jsfiddle.net/yrygy/270/ , worked fine. but, have chart in same view. line chart.
this second chart assume realign labels too. how can use function single chart container id, or type of chart, like:
var chart = new highcharts.chart({ chart: { renderto: 'container', type: 'column' },
the function im using:
function realignlabels(serie) { $.each(serie.points, function (j, point) { if (!point.datalabel) return true; var max = serie.yaxis.max, labely = point.datalabel.attr('y') if (point.y / max < 0.35) { point.datalabel.attr({ y: labely - 100, }); } }); }; highcharts.series.prototype.drawdatalabels = (function (func) { return function () { func.apply(this, arguments); if (this.options.datalabels.enabled || this._haspointlabels) { realignlabels(this); } }; }(highcharts.series.prototype.drawdatalabels));
line chart affected: http://prntscr.com/9srmpv
you can modify wrapper:
highcharts.series.prototype.drawdatalabels = (function(func) { return function() { func.apply(this, arguments); if ((this.options.datalabels.enabled || this._haspointlabels) && this.chart.options.chart.realignlabels) { realignlabels(this); } }; }(highcharts.series.prototype.drawdatalabels));
as can see have added new option if statement. if want realign labels have write:
chart: { type: 'column', realignlabels: true, animation: false },
i have added animation parameter. without parameter realign labels not work when hide , show series.
example: http://jsfiddle.net/yrygy/497/
Comments
Post a Comment