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

Building an OHLC chart with last quarter's stock data


When we return to our office, we contact the IT team to get a JSON feed of the company's stock prices. They have one that was created a few months back. This gives us the stock prices of the last three quarters, which should be enough to get us started. We load the JSON feed in our browser and see that it is an array of arrays. For each array corresponding to a day, there are five elements: the date, the opening price, the high price, the low price, and the closing price:

[
["30-Sep-2012", 16.91, 17.29, 16.86, 17.16],
["29-Sep-2012", 16.70, 16.91, 16.46, 16.89],
...
]

With an understanding of the format of our remote data, we begin coding our chart using the following steps:

  1. We start by including the OHLC plugin file. We also include the highlighter plugin so that we can show all the prices when the user highlights each day. In addition, we want the plugins that allow us to format our dates on the axis and rotate them:

    <script src="....