O'Reilly logo

Learning jqPlot by Scott Gottreu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a legend

As we study the chart, we lose track of which line represents revenue and which represents profit. We'll need a legend to solve this problem:

  1. We start by adding labels to each of our series objects. We add a label object to our empty object for the first data series. For the second series, we add the label option alongside the existing yaxis option.
    title:'Monthly Revenue & Profit',
    series:[
      { label: 'Revenue' },
      { label: 'Profit', yaxis:'y2axis' }
    ], 
  2. Next, we add a legend option. In order for the legend to appear, we must set the show option to true. We also set placement to outsideGrid. The other two options available to us are insideGrid and outside. The outsideGrid option will place the legend outside the grid, but inside the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required