Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Add Legend title

Open dhuallanca opened this issue 9 years ago • 9 comments

FEATURE requests

Expected Behavior

Add title for legend

Current Behavior

Legend doesn't sopport title

Possible Solution

Steps to Reproduce (for bugs)

1. 2. 3. 4.

Context

user expectation

Environment

dhuallanca avatar Jul 05 '17 22:07 dhuallanca

@dhuallanca what kind of title do you envision for the legend?

etimberg avatar Jul 06 '17 00:07 etimberg

@etimberg, I am using doughnut chart, I would like to have a title(Label) on the top of legends.

dhuallanca avatar Jul 07 '17 19:07 dhuallanca

Second this. If I have a data series with days of the week, it'd be nice to have 'Week' as the legend title. This is even more important when a chart's independent variable and series are both True/False.

ccario83 avatar Dec 29 '17 03:12 ccario83

What's the difference with the chart title? Can you provide a mockup of what you are trying to build?

simonbrunel avatar Dec 29 '17 07:12 simonbrunel

What's the difference with the chart title? Can you provide a mockup of what you are trying to build?

image

dhuallanca avatar Jul 01 '19 17:07 dhuallanca

@dhuallanca , Hey i want to work on this ,can you explain a bit more about this

jatiny17 avatar Sep 07 '19 13:09 jatiny17

@jatiny17 , I want to add a Legend title on the top of legends items.

image

dhuallanca avatar Sep 10 '19 21:09 dhuallanca

same problem, any help with it?

RahulChouhan96 avatar Sep 28 '19 07:09 RahulChouhan96

I find the way to hack this behavior, however it's not supported by default.

legend.labels.generateLabels = chart => {
      var data = chart.data;
      let labels = Chart.defaults.global.legend.labels.generateLabels(chart);
      let title = {
        text: 'Legend Title',
        strokeStyle: 'transparent',
        fillStyle: 'transparent',
        lineWidth: 0
      };
      return [title, ...labels];
    };

image

image

huyit88 avatar Nov 05 '19 10:11 huyit88