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 reusable plot objects


We begin to prepare everything for our next chart, but we stop ourselves. Our last two charts for the VPs are bar charts and have very similar options. Several of the charts for the divisional managers could use the same code but with a different data source.

You mention we should DRY up our code. I give you a look. You continue by telling me it means, "Don't Repeat Yourself." I continue to look at you with slight bewilderment. "What?" you say, "I've been reading The Pragmatic Programmer."

This is sound advice. There may be a bit more up-front work to create these objects, but the savings in time and energy for each subsequent chart will be worth it.

We look back at our existing bar charts and distill the most common options. We open themes.js so we can get started creating an object to contain our default settings:

  1. We start by creating the defaultBarObj variable as a function expression. This means we'll store an unnamed function in a variable. We will pass in...