c3 icon indicating copy to clipboard operation
c3 copied to clipboard

Chart resize default behaviour

Open lblb opened this issue 12 years ago • 7 comments

Hello, If you have a div container without width and height predefined in style, chart tends to scale up any time browser window is resized (doesn't matter you reduce size or increase it). The same happens if chart is drawn in resizable dialog.

A workaround is to set height of container in style, then chart fills in available width and resizes nicely without any extra code.

The example of issue:

    <script type="text/javascript">
    $(document).ready(function(){
        $("#dialog").dialog({open:function(){
            $("#dialog").append("<div id='chart'></div>");

        var chart = c3.generate({
            data: {
                columns: [
                    ['data1', 30, 200, 100, 400, 150, 250],
                    ['data2', 130, 100, 140, 200, 150, 50]
                ],
                type: 'bar'
            }
        });
        }});
    });
    </script>
</head>
<body>
    <div id="dialog"></div>
</body>

lblb avatar Apr 10 '14 07:04 lblb

add size for the chart to avoid it helped me var chart = c3.generate({ size: { height: 300 }, ......});

vivekn91 avatar Apr 10 '14 11:04 vivekn91

Yes, I know this workaround, you can set height to dom element or in chart config. My aim was to create a resizable dialog, which could be expanded both horizontally and vertically. Even if I hook to resize event and change chart size there, it will not update well because of this default behavior.

lblb avatar Apr 10 '14 11:04 lblb

Hi, I added onresize and onresized event handlers and I think these can be used to do something before/after resize of chart.

For this issue, onresize event can be used because if the height of the parent of bindto element changes in onresize, the height of the chart will change also in consecutive resize processing.

Would this solution work for your issue?

In addition, if you display only a chart in the dialog, I think you can bind the chart to that dialog directly by setting bindto = '#dialog'.

masayuki0812 avatar Apr 12 '14 12:04 masayuki0812

Thanks, sounds good, I'll try it out later.

lblb avatar Apr 17 '14 09:04 lblb

I'm not sure this would solve the original issue, which was the chart growing when the window is resized, not the bindTo element. I also come across this when resizing the developer tools attached to the window.

webmaven avatar Apr 18 '14 14:04 webmaven

@webmaven You're right. Chart growing is original issue. I think that has been fixed by #105 #171 together.

masayuki0812 avatar Apr 24 '14 06:04 masayuki0812

:+1:

webmaven avatar Apr 24 '14 15:04 webmaven