Skip to content

Instantly share code, notes, and snippets.

@jeremywrowe
Created August 29, 2012 04:33
Show Gist options
  • Save jeremywrowe/3506869 to your computer and use it in GitHub Desktop.
Save jeremywrowe/3506869 to your computer and use it in GitHub Desktop.
highcharts - show label for first and last data points in a series
plotOptions: {
line : {
dataLabels : {
enabled : true,
formatter: function() {
var first = this.series.data[0],
last = this.series.data[this.series.data.length - 1];
if ((this.point.category === first.category && this.point.y === first.y) ||
(this.point.category === last.category && this.point.y === last.y)) {
return this.point.y;
}
return "";
}
},
},
}
@katja2016
Copy link

Nice!

@ScorpioT1000
Copy link

performance impact

@nilsrunde
Copy link

Great, thanks!

@ViieeS
Copy link

ViieeS commented May 16, 2019

For the latest versions:

formatter() {
    return (this.isFirst || this.isLast) ? this.value : '';
},

https://api.highcharts.com/highcharts/xAxis.labels.formatter

@dhanashrisakharkar
Copy link

thank you soo much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment