Chart.js: Add Legend title

Created on 6 Jul 2017  Â·  9Comments  Â·  Source: chartjs/Chart.js

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

enhancement

Most helpful comment

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

image

All 9 comments

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

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

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.

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

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

image

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

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

image

same problem, any help with it?

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

Was this page helpful?
0 / 5 - 0 ratings