Chart.js: Get bar width after render?

Created on 16 Aug 2017  ·  5Comments  ·  Source: chartjs/Chart.js

Context

I have looked through the chart object and I am battling to find the bar width in pixel value anywhere.

Is this stored in the object? or is there anyway i can get this?

Thanks

support

All 5 comments

You can get the bar width as follows:

var meta = myChart.getDatasetMeta(0);
var width = meta.data[0]._model.width;

That works perfectly thank you very much 👍
@simonbrunel

Thanks @nagix ;)

For future readers....use the .height property if you are using a horizontal bar chart as .width will be undefined.

is there a way of getting both height and width of a bar in bar chart?

Was this page helpful?
0 / 5 - 0 ratings