score:1

Accepted answer

well it prints out an array of labels, because you pass in for one dataset multiple labels.

if you want a label for each datapoint, you need to pass multiple datasets. the labels, in most charts in chart.js define your x-axis. for example dates.

then you define a dataset with a label. which can have multiple datapoints. for example, "usage of javascript". in your data array you then have the matching data for the x-axis. if your labels have three values (jan, feb, ma) then your datasets[0].data[] should also have three values. the first would be matching for "jan", the second for "feb" etc.

but thats only one dataset. and only one label for it. so only one entry in the legend. if you want mulitple entries, you need to define multiple datasets.

labels: ['jan', 'feb', 'mar'],
datasets: [
  {
   label: ['usage of javascript'], 
   backgroundcolor: this.getbackground(),
   data: [10, 20, 22]
  },
  {
   label: ['usage of php'], 
   backgroundcolor: this.getbackground(),
   data: [16, 18, 20]
  }
 ]

score:0

answers to the questions:

  1. how do i get legend with this label and colors?

by using legendcallback method in your options object passed to chart

  1. how do i get tool tip showing the label with the data point rather than each labels with the data point?

in another chart option you can define what you need in tooltip:

  tooltips: {
      mode: 'single',
      callbacks: {
      label: function (tooltipitems) {
      return tooltipitems.ylabel // tooltipitems has other options which can be probed
            }
          },
        }

  1. how would one add an image to the tooltip / label?

adding an image tag <img src="https://link-to-image" /> in generating legend or tooltip works fine.


Related Query

More Query from same tag