Chart.js: [FEATURE] Text wrap long legend text

Created on 24 Nov 2016  ·  3Comments  ·  Source: chartjs/Chart.js


My ChartJs legend text is overflowing in the same line when the text is too long. Is there any parameter that I can use to enable text-wrap.

Expected Behavior


It will be nice to have something like the following, if the width is exceeding the set value. It will be auto-wrapped.

legend: {
    itemStyle: {
        width: 90 // or whatever, auto-wrap
    },
}

Current Behavior



Legend text is overflowing in the same line when the text is too long

Possible Solution

As suggested above

Context



While assigning a long text for legend

Environment

  • Chart.js version: 2.3.0
  • Browser name and version: All
help wanted enhancement

Most helpful comment

I read other articles and all concludes that you need to remove native chart.js legend and replace by another html div to have multiple line legends. I think that is important to have an option for this in the bundle of chart.js, not as outside solution

All 3 comments

If someone familiar with the core can give some pointers and direction, actually I can try to help.

@nanospeck the legend code is in https://github.com/chartjs/Chart.js/blob/master/src/core/core.legend.js

Off the top of my head, I'm not sure what the best thing to start with is. You'd need changes to fit which measures the size of the legend and also changes to the drawing code

I read other articles and all concludes that you need to remove native chart.js legend and replace by another html div to have multiple line legends. I think that is important to have an option for this in the bundle of chart.js, not as outside solution

Was this page helpful?
0 / 5 - 0 ratings