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

Modifying the data array and the tooltip


In order to remedy this problem, we need the closing price to be the first y value in our data array. We can accomplish this by modifying our dataPull function. We save the previous code as a new file and start making our changes executing the following steps:

  1. We create a new array called stocks, and then loop through the remoteData array. We add the date, which is the first element, and then we add the closing price, which is the last element in the remoteData array:

    ...
      function dataPull(remoteData,options) {
        var stocks = new Array;
        for(var x=0;x<remoteData.length;x++){
          stocks[x] = new Array;
          stocks[x].push(remoteData[x][0],remoteData[x][4]);
  2. We now have our x and y values, so we loop through the rest of the prices in the child array. Once we finish working through remoteData, we return our new array to jqPlot:

          for(var y=1;y<remoteData[x].length;y++){
            stocks[x].push(remoteData[x][y]);
          }
        }
        return...