1- Why the parent div does not adjust to the canvas? (if I try other elements instead CanvasJS it works fine)
The height of canvas in CanvasJS Library is 400 pixels by default. That’s the reason it doesn’t adjust to it’s parent div even when you don’t provide height or width property.
2- As I removed the Title and moved the legend to the right, there is a huge gap now on the top and on the bottom of the Chart. Is there a way to remove it?
The gap also exists because of the same reason i.e. height of canvas. You can manually set the height of chartContainer. This will remove the extra gap on top and bottom of chart.