chartjs / chartjs/chartjs-plugin-datalabels
Getting height of label in scriptable options?
- Dominant language
- JavaScript
- Stars
- 920
- Forks
- 507
- PR merge metrics
- No merged PRs in 30d
Description
I'm looking to implement functionality that will display label inside or outside of bar, depending on how much space is available. The way I've set to do this is by passing a function to `align` and then doing some calculations based on x,y coordinates of individual charts and chart size.
The sample code below works, but to it uses a fixed threshold, where I would like to compute it based on label width/height.
```js
datalabels: {
align: context => {
let meta = context.chart.getDatasetMeta(context.datasetIndex),
bar = meta.data[context.dataIndex]._model,
threshold = 15
// label = context.chart['$datalabels'].labels[context.datasetIndex][context.dataIndex]._model;
if (bar.y + threshold > context.chart.chartArea.bottom) {
return 'end'
}
return 'start'
}
}
```
I've tried using `label` (commented in above code) to try and get sizing info, but all seem to be null on first pass (`_model`, `_hitbox._rect`, ...)
Any ideas, suggestions? Thanks.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.