Book Image

jQuery for Designers Beginner's Guide Second Edition

By : Natalie Maclees
Book Image

jQuery for Designers Beginner's Guide Second Edition

By: Natalie Maclees

Overview of this book

Table of Contents (21 chapters)
jQuery for Designers Beginner's Guide Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. 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.

  2. Next, we need to get the actual width of the available content area on our page. As our CSS code is fluid, this will change depending on the width of the browser...