Making FusionCharts Occupy 100% Width and Height of Container

Under certain circumstances, one may want FusionCharts to occupy 100% (or a certain percentage) width and height of the container element. This can be achieved using two methods using the jQuery Plugin for FusionCharts.

Using percentage value for width or height

If you set width: "100%" and/or height: "100%", it sets the HTML width and height of the object/embed tag of the chart to 100%. This makes the chart occupy the entire area of the parent container.

$("#myChartContainer").insertFusionCharts({
    width: "100%", height: "100%",
    data: "",
    dataFormat: "XMLData"
});

You can set any percentage value to make the charts occupy that percentage of width and height of the container element.

This method is even available if you are using standard FusionCharts.js file.

Using "auto" for width and height of the chart

This is a feature with FusionCharts jQuery plugin were, if you set width: "auto" and/or height: "auto", it sets the dimension of the chart to parent.width() and parent.height() respectively in pixels.

$("#myChartContainer").insertFusionCharts({
    width: "auto", height: "auto",
    data: "",
    dataFormat: "XMLData"
});

This approach is slightly different from the first (percentage) method in the sense that it sets the dimensions of the chart in pixels and it does not change in case the parent element’s dimension changes.

Precautions of using the percentage and auto methods

The above two methods have one limitation: In case the container has no set dimension or in case the container is not fully rendered, the chart does not receive the proper dimension. Owing to the fact that FusionCharts v3 and FusionCharts Free does not support native resizing as of now, it might render oddly.

As a workaround to the above issue, if we render the chart after the page is loaded using jQuery’s $(document).ready() event, this issue is partially fixed.

$(function() {
    $("#myChartContainer").insertFusionCharts({
        width: "auto", height: "auto",
        data: "",
        dataFormat: "XMLData"
    });
});

6 Replies to “Making FusionCharts Occupy 100% Width and Height of Container”

  1. It doesn´t work for me! when i set 100% for width, chart gets very tiny and align is in the left of its containers. And “auto” has the same behavior in some/my case.

    1. Well… it seems to be a typical sign of the issue I mentioned under the section “Precautions of using the percentage and auto methods” at the end of the above post.

      Did you try with the workaround I suggested?

  2. Hey I was trying the workaround , it does not seem to work in my case 🙁
    (using FusionCharts Free)
    here is piece of code :

    Loading FusionCharts!

    Cheers

Leave a Reply