简体   繁体   中英

Chart js (plugin annotation) label overflow issue

Need to know possible solutions to resolve such issue: 在此处输入图像描述

My annotation object looks like this:

{
      type: 'label',
      borderRadius: 0,
      borderWidth: 0,
      content: content,
      font: {
        size: 8,
        weight: 'bold'
      },
      position: {
        x: 'center',
        y: 'end'
      },
      xValue: name,
      yValue: value
    }

Is any way maybe to add a free space above bar to show annotation properly?

PS I can't set max value for Y because it's dynamic

I could set the clip option to false in order to draw the label outside of chart area.

Here you can find the doc: https://www.chartjs.org/chartjs-plugin-annotation/latest/guide/configuration.html#top-level-options

Here an example:

const options = {
  plugins: {
    annotation: {
      clip: false,
      annotations: {
        ...
      }
    }
  }
};

You can add padding to the graph. options: { layout: { padding: 40 } } https://www.chartjs.org/docs/latest/general/padding.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM