c3 icon indicating copy to clipboard operation
c3 copied to clipboard

Chart resizing workaround no longer works #1714 Reporting again

Open Sreelakshmigc opened this issue 9 years ago • 4 comments

There is already an issue rised regarding this, Did not get any responses back, so I am creating a new one.

When rendering in hidden containers, such as a , c3 charts do not resize properly when the container becomes visible.

A workaround was to invoke $window.trigger('resize') when the container is made visible. This worked in 4.10. It no longer works with 4.11.

if there is a new and improved solution, please advise.

Please provide an answer to this asap it is very crucial.

Also linking the stackoveflow link which has details of this workaround . //c3/d3 charts require a resize trigger to disply in bootstrap //refer http://stackoverflow.com/questions/26003591/c3-chart-sizing-is-too-big-when-initially-loaded

Sreelakshmigc avatar Mar 07 '17 07:03 Sreelakshmigc

Still waiting for an answer. This is very critical for me, please help me. If I do not have a solution, I can not upgrade to the latest version of c3 which has awesome updates. Please help me

Sreelakshmigc avatar Mar 09 '17 11:03 Sreelakshmigc

Any inputs on this please

Sreelakshmigc avatar Mar 13 '17 05:03 Sreelakshmigc

At the initialization, C3 try set width value from bind element, but if can't get the correct width value, it tries to get from its parent node.

  • https://github.com/c3js/c3/issues/1927#issuecomment-271827551

When chart is initialized in hidden container, probably (or in most cases) it can't set correct width. If you can get correct width/height from visible element, then you can set the chart's size manually.

chart.resize({ 
    width: width-value,
    height: height-value
});
  • API: http://c3js.org/reference.html#api-resize

To have more detailed look, provide your code somewhere (jsfiddle, jsbin, codepen, etc.)

netil avatar Mar 14 '17 07:03 netil

Hi Netil,

Thank you sooo much for your time and comments, much appreciated. chart.resize() helped me with the solution with little changes in the way width is being passed. Please see below the code that worked for me

As I am using pivottable interface to draw the charts, I am passing the size width as one of the rendererOptions before calling pivot() and using the same in the c3_renderers resize event.

options["rendererOptions"] = { c3: { size: { width: $("#"+divId).width() }} };

$("#"+divId).pivot(input, options);

c3_renderers.js :

if ((base1 = opts.c3.size).width == null) { base1.width = opts.c3.size.width; }

var chart = c3.generate(params);

    chart.resize({
        width: base1.width,
        height: base2.height
    });

Hope this helps for anybody looking for a solution. Thanks again

Sreelakshmigc avatar Mar 16 '17 05:03 Sreelakshmigc