Reputation: 7833
I have a pie chart using chart.js in my Ionic 4 / Angular application, with the following options...
let options : ChartOptions = {
responsive: true,
maintainAspectRatio: false,
legend: {
position: 'bottom',
labels: {
boxWidth: 20
}
},
My chart looks like the following, but I would like the gap as shown below to be smaller, ie the legend closer to the pie chart.
Is there any way to reduce this gap?
I have just noticed it is due to the size of my view port. For example, on a phone screen:
Now if I make the vie responsive, and stretch the view, I can see the legend always stick to the bottom of the view, so when stretched to the chart is large the legend is now closer:
So, the legend us "docked" to the bottom of the view.
Upvotes: 6
Views: 2806
Reputation: 7833
One propose solution (perhaps there is a better way - still be interested...)
I found, in my case, I could do this just by adjusting the bottom of my container.
Using the following markup..
<div id='graphc'>
<canvas (click)='updateClick($event)' #mygraph></canvas>
</div>
and the following css
#graphc{
width:100%;
height: 100%;
padding: 10px;
padding-bottom: 120px; // <-- this moves it up
}
This at least does what I was after, though if I stretch, I do always have the gap....
Maybe I could make the css "dynamic" to fix this
Upvotes: 0
Reputation: 622
I think the space might be due to your css. Try changing that. This solves your problem as well.
legend:{
position: 'bottom',
labels: {
boxWidth: 20,
padding: -10
}
}
Upvotes: 1