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

Adding extra canvas elements


Our overlayLogo function will calculate the new height and position for our logo. Then, we will use the drawImage method to convert the image and make it part of the main canvas. We wrap all of this in a setInterval function because we have to wait for jqPlot to render all the canvas elements before we can add our image. Perform the following steps to add extra canvas elements:

  1. We start by setting yPos to bottom if nothing is passed in for this parameter. When calculating coordinates for a canvas element, we begin at the upper-left corner. So, we declare variables for our height and the x and y coordinates. Next, we create a variable to hold our setInterval function as follows:

    function overlayLogo(id, scaledWidth, yPos) {
      if(typeof(yPos) === 'undefined') { yPos = 'bottom' };
      var height = 0, top = 0, left = 0, canvas = '';
      var checkCanvas = setInterval(function() {
  2. jqPlot does not add an ID to the canvas elements it creates, so we need to locate our canvas...