Book Image

Learning jqPlot

By : Scott Gottreu
Book Image

Learning jqPlot

By: Scott Gottreu

Overview of this book

Table of Contents (19 chapters)
Learning jqPlot
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a pie chart for each division with product category revenue


We decide that we will create all three divisional pie charts and place them side by side. This way, all the VPs will be able to compare each division. We do so by executing the following steps:

  1. We start by repurposing our dataPull function. This time we make use of the options object passed into the function. We pass in the name of the division in hashName, which corresponds to an object in our JSON feed:

    ...
    <script>
    function dataPull(remoteData,options) {
      var obj = remoteData[options.hashName];
      var data = new Array();
      var i = 0;
  2. We then loop through each child object in our divisional object. We build an array element for each product category with a label and the dollar value. Then, we wrap our data array in another array and return it to jqPlot:

      for (var name in obj) {
        data[i] = [name, obj[name]];
        i++;
      }
      return [data];
    }
  3. For each chart, we use the same data feed. We decide to experiment with the...