Time for action – calculating the ideal size for charts and graphs
We'll keep working with the files we created in the previous section. Perform the following steps to dynamically set the width and height of our charts and graphs according to the width of the browser window:
- Open your
scripts.js
file. We'll want to add a few quick calculations. First up, let's set a preferred width for our graphs and charts, as follows:$(document).ready(function(){ var preferredWidth = 450; $('#menu').visualize({ ... }); $('#eaten').addClass('accessHide').visualize({ ... }).appendTo('#pie-container').trigger('visualizeRefresh'); });
We created a variable named
preferredWidth
. Recall that a variable is just a container—in this case, the variable contains the size in pixels that we'd like our charts and graphs to appear by default. - Next, we need to get the actual width of the available content area on our...