A Very Easy Way to Adjust the Size of Pie or Doughnut Charts of Chart JS
The default Chart js doughnut and pie Charts is responsive, which means the whole charts would take up all the screen with a width of 100%.
One simple way to adjust their size is to wrap them around with a div tag which has width set to, say 50%.
If you want to change their position, you can also adjust the div tag's margin-left style attribute. If your pie chart has a 50% width and you also want to position it in the middle, make sure you subtract the 50% from 1 and divide by 2 to get the value for margin-left.
For thie example, 1 - 50% = 50%, 50% / 2 = 25%, value for margin left is 25%.
Sample Code
<div style = "width:50%;margin-left:25%"> <canvas id="myChart"></canvas> </div>
Playaround
50%
25%
Comments
Post a Comment