Search code examples
highcharts

Customize captions


Is there any way to group the captions in the chart? Attach an image with an example. What I wanted is, in the red line enter an enter ("\ n" or "br"). It's possible? Thank you

Image: https://pasteboard.co/HXPlaT2.jpg


Solution

  • You can wrap layoutItem function in Highcharts.Legend.prototype and start a new line when a fake newLine property will be found in series options:

    // If the item exceeds the width, start a new line
    if (
      horizontal &&
      (
        this.itemX - padding + itemWidth > maxLegendWidth ||
        item.userOptions.newLine
      )
    ) {
      this.itemX = padding;
      this.itemY += itemMarginTop + this.lastLineHeight +
        itemMarginBottom;
      this.lastLineHeight = 0; // reset for next line (#915, #3976)
    }
    

    You should put this property in the series which you want to start from the new line:

    , {
      name: 'Manufacturing1',
      data: [43934, 52503, 57177, 69658, 9031, 119931, 137133, 54175],
      newLine: true
      }
    

    jsFiddle (working for v10.2.1 and lower): https://jsfiddle.net/BlackLabel/zbcLeyat