Getting the length of a horizontal bar after animation #320
Answered
by
stockiNail
thoughtassassin
asked this question in
Q&A
-
I created a Stack Overflow with this question. Here is the codepen that I am working on. I want to get the width of the bar in the offset function after the chart animates. Is there a way to do that? Currently, with the animation on the width returns |
Beta Was this translation helpful? Give feedback.
Answered by
stockiNail
Jun 1, 2022
Replies: 1 comment
-
@thoughtassassin I think you should use Here is the doc from CHART.JS: /**
* Gets the current or final value of each prop. Can return extra properties (whole object).
* @param {string[]} props - properties to get
* @param {boolean} [final] - get the final value (animation target)
* @return {object}
*/
getProps(props, final) {
...
}
} To get the value of width at the end of animation, have a look to following code, taken from you codepen: offset: function(context) {
const chart = context.chart;
const area = chart.chartArea;
const meta = chart.getDatasetMeta(context.datasetIndex);
const model = meta.data[context.dataIndex];
// passing true you can get the final value of element property
// at the end of animation
const {width} = model.getProps(['width'], true);
console.log('width: ' + width);
return 4;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
simonbrunel
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@thoughtassassin I think you should use
getProps
method of data element.Here is the doc from CHART.JS:
To get the value of width at the end of animation, have a look to following code, taken from you codepen: