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

Preface

The term "Big Data" is all over tech news. But what does it really mean? Big Data refers to the problem of trying to process and analyze large amounts of data. Generally, Big Data refers to the petabytes of data, which is over 1 million gigabytes. You are likely to face your own Big Data issues, just on a smaller scale. If you only have one web server, processing or analyzing a database of only one gigabyte can be overwhelming.

Another part of the Big Data problem is the source and format of the data. It is coming from many sources and it's not easy to match all of the data points. You probably have years of transactional data in a MySQL database, as well as APIs to Google Analytics, Facebook, Twitter, and any other services your company uses.

Once you can figure out how to process the data, you need to do something with it. That's where jqPlot comes in. Using charts to display large datasets makes it easier to see trends or correlations in the data. jqPlot allows you to create charts quickly so that you can move on to analyze your data.

Many technical books give examples that don't match anything you might deal with in the real world. I'm writing this book about the various problems we face working in the fictional company jQ Big Box Electronics. We will work through real-world examples that reflect the reality of the "Big Data" world we live in. I hope that placing these examples in a practical context will help you understand the rationale for using a certain chart for a particular dataset and build on the skills you will acquire from this book.

What this book covers

Chapter 1, Getting Started, will briefly give an introduction on how to create a jqPlot object and how the plugin handles data. Then, we'll start creating our first charts, as well as looking at different options for formatting lines and marks.

Chapter 2, More Line Charts, Area Charts, and Scatter Plots, discusses the different ways in which you can load data into your chart, including using AJAX to a remote service. Then, we'll move on to discussing what area charts and scatter plots are, and their best uses.

Chapter 3, Bar Charts and Digging into Data, discusses the best uses of bar charts. We'll also see different options for axis and tick labels including rotatable labels. We'll finish up with clickable data points and will look at how to use these to drill down into more complicated data.

Chapter 4, Horizontal and Stacked Bar Charts, teaches you about horizontal and stacked bar charts. We'll also look at axis padding and positioning of data point labels.

Chapter 5, Pie Charts and Donut Charts, discusses the specific uses of pie charts and donut charts. We'll also see some specific options for pie charts.

Chapter 6, Spice Up Your Charts with Animation, Tooltips, and Highlighting, teaches how to animate your own charts and how to create tooltips. We'll also cover data point highlighting and cursor highlighting.

Chapter 7, Stock Market Charts – OHLC and Candlestick Charts, discusses OHLC and candlestick charts, and their specific uses. We'll also learn the method to format the text included in the tooltips.

Chapter 8, Bubble Charts, Block Plots, and Waterfalls, looks at some different charts that are heavier on the visualization of data over the representation of the data.

Chapter 9, Showing Real-time Data with Our Charts, discusses the methods that allow us to redraw or recreate a given plot after it is has been generated. We'll take this newfound knowledge and see how to update our charts automatically at set intervals.

Chapter 10, Beautifying and Extending Your Charts, explains how to create different themes for our plots and the various CSS options available to style our charts.

Chapter 11, Bringing it All Together, combines everything you have learned and merges the different chart types into one plot, as well as styling your new charts. You will also see how jqPlot can be extended with the new rendering plugins.

Appendix, Answers, helps us find the answers to all the learning questions found throughout the book.

What you need for this book

You use jQuery for most of your projects, so you're well on your way to learning jqPlot. Here's what else you'll need to get up and running with jqPlot:

  • Your favorite IDE or text editor. If you don't have a favorite, you can try out Sublime Text, http://www.sublimetext.com, for Mac OS, or Notepad++, http://notepad-plus-plus.org/, for Windows.

  • Your choice of browser. JqPlot will work with IE6 and higher, but needs extra plugins to replicate the canvas functionality found in modern browsers. These additional plugins are included with jqPlot.

  • The latest version of jQuery, which is available at http://jquery.com/download/. Either Version 2.x or 1.x will work with jqPlot, but if you need support for IE7 or IE8, you will need to use jQuery 1.1x.

  • The latest version of jqPlot, which is available at https://bitbucket.org/cleonello/jqplot/downloads/.

That's it! You don't need anything else. Ideally, you would incorporate your charts into a larger project such as your company intranet. This would also be the best place to get the data for your charts.

Who this book is for

This book is for everyone who uses jQuery for their projects. More specifically, this book is for everyone who has ever experienced something like the following scenario: "We've got 3 years of data that we need to analyze and chart by Friday. Work your magic."

I'm writing this book to help you solve problems. You're a developer, so you are smart and curious. If you're like me, you like seeing how data is interconnected. So, I want to help you determine the best way to present the data that your boss dumped on you.

As you begin working, I want to help you begin thinking of other data points you could bring into your reports. As you begin thinking of new connections, this will help those who will be looking at the data when you're done. In the end, I want to make you a hero to your boss.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "For the yaxis option, we set our label and use the formatString option to format our values as currency."

A block of code is set as follows:

   <script>
   $(document).ready(function(){
     var secondPlot = $.jqplot ('secondChart', [[[5,4],[10,7],[15,6],[20,9]]]);
   });
   </script>
   <div id="secondChart" style="width:400px;"></div>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<script src="../js/jqplot.dateAxisRenderer.min.js"></script>
<script>
$(document).ready(function(){

  var revenue = [['2012-07-20', 807403], ['2012-08-20', 755840], ['2012-09-20', 775304]];
  var profit = [['2012-07-20', 193793.82], ['2012-08-20', 183221.56], ['2012-09-20', 192797.31]];
  var electronics = [['2012-07-20', 116276.29], ['2012-08-20', 95867.97], ['2012-09-20', 120591.27]];
  var media = [['2012-07-20', 27596.25], ['2012-08-20', 32396.47], ['2012-09-20', 26709.06]];
  var nerd_corral = [['2012-07-20', 49921.28], ['2012-08-20', 54957.12], ['2012-09-20', 45496.98]];

  var rev_profit = $.jqplot ('division_profit', [revenue, profit, electronics, media, nerd_corral],
  {

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "We test our chart, and a trend line for DVDs/Blu-ray is rendered since we did not pass a query string."

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title through the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/1168OS_ColoredImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.