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

Reaping the benefits of the DRY code


We have one more chart to create for the VP's dashboard in the form of a bar chart showing product returns. We were able to get the data for each return category for the last 12 months in a JSON feed. We can reuse defaultBarObj and color_theme, which will speed up the building of our chart as follows:

  1. We open the chart we created a few weeks ago, 1168_03_05.html. Since all of these charts are going to be combined into one page, we need to create separate variables for our series objects and our functions to format the remote data as follows:

    $(document).ready(function(){
      var returnsSeriesObj = [];
      var returnsDataPull = function(remoteData,options) {
        return [remoteData];
      };
  2. We pass in our new series object, CategoryAxisRenderer, and our new returnsDataPull function. Once we create returnsPlotObj, we set varyBarColor to true. Our first version of this chart had the same color for each bar since they are technically all in the same series. Using varyBarColor...