Skip to content

How can I show the label on the point of the line. #215

Answered by simonbrunel
pakorn33 asked this question in Q&A
Discussion options

You must be logged in to vote
var barmain1 = new Chart(barChartCanvas, {
  plugins: ChartDataLabels,
  //...

This should be:

var barmain1 = new Chart(barChartCanvas, {
  plugins: [ChartDataLabels], //< array of plugins
  //...

My guess is that when you create your first chart (graphtype === 'bar' apparently), Chart.plugins.unregister hasn't been called yet, so the datalabels plugin is still registered. But then, when graphtype === 'line', the plugin is unregistered and since you misused the plugins chart config, no label are displayed. You should also move everything from Chart.plugins.unregister before creating a new chart (and it should be called only one time).

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@pakorn33
Comment options

Answer selected by pakorn33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants