question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Displaying custom labels from an array

See original GitHub issue

I’ve got an array of data points, and another one of data label strings. I’m graphing the points and would like to use the strings as labels. How do I use this plugin to do so? Here’s what I’ve got right now:

datasets: [{
  label: 'Phenological States',
  data: phenoArray(historicalData).values,
  datalabels: phenoArray(historicalData).labels,
  // ...
}]

Edit(SB): code formatting

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
simonbrunelcommented, Jan 20, 2018

I added some docs and a sample how to display custom labels (bea5b4be8dd99a4).

2reactions
simonbrunelcommented, Jan 15, 2018

It’s possible, but dataset.datalabels is reserved for the plugin options so can’t be used to store custom labels. You can either use the Chart.js built-in data.labels (category scale) or you can store them under whatever other unreserved name in the dataset (e.g. dataset.labels). Then you need to define a custom formatter and use context to reach your values.

If you use data.labels (fiddle):

new Chart('id', {
  data: {
    labels: phenoArray(historicalData).labels,
    datasets: [{
      label: 'Phenological States',
      data: phenoArray(historicalData).values
    }]
  },
  options: {
    plugins: {
      datalabels: {
        formatter: function(value, context) {
          return context.chart.data.labels[context.dataIndex];
        }
        // ... other options ...
      }
    }
  }
}

If you use dataset.labels (fiddle):

formatter: function(value, context) {
  return context.dataset.labels[context.dataIndex];
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom label from using separate array in Chart JS
In the above code data.price is storing the price array. I need to pass the store details with it and show it in...
Read more >
Use Custom Label in Lightning Component array of String ...
Save this question. Show activity on this post. I want to build a component that looks like the Radio Group Alternate one of...
Read more >
Label and Value in an array - help needed :( - ACF Support
Here's what I'm trying to achieve and works when only one option is selected. It prints the label as the anchor and the...
Read more >
Analyzing an image with a trained model - Rekognition
Custom labels are returned in an array of Custom Label objects. Each custom label represents a single object, scene, or concept found in...
Read more >
register_post_type() | Function
An array of labels for this post type. ... In general, you should always prefix your post types, or specify a custom `query_var`,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found