How to resize the Morris Charts?

Riot Zeast Captain picture Riot Zeast Captain · Jun 15, 2016 · Viewed 11.3k times · Source

I'm resizing the page by clicking 'menu toggle button', but when am doing so the Morris charts are not resized, I tried to trigger it, but its not working. I added a line of code in my js $(window).trigger('resize'); but this dint worked. can any body help me? as I'm not aware of resize option in jQuery.

Thanks -Riot Zeast Captain

Answer

Azhar picture Azhar · Jul 29, 2016

html:

<div id="area-chart" class="col-sm-12"></div>

Make a variable and all Morris chart initialization you required but make sure not to include the following properties while initializing Morris chart redraw: true and resize: true

var bar = Morris.Bar({......});

Here the jquery resize function magic which trigger when ever div resizes no need to trigger window resize.

$('#area-chart').resize(function () {
  bar.redraw();
});

Whenever DIV resize the Morris Chart automatically fit to it's parent DIV which is col-sm-6.

This solution give you the size of chart according to the parent div size.

You don't need to add click function also.