Download the current version of jqPlot and extract the files to your web server. We'll create the most basic chart we can, as shown in the following steps:
<!doctype html> <head> <title>Learning jqPlot</title> <meta charset="utf-8"> <link rel="stylesheet" href="/css/jquery.jqplot.min.css"> <script src="../js/jquery.min.js"></script> <script src="../js/jquery.jqplot.min.js"></script> </head> <body>
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
id
to firstChart
so that jqPlot will know where to build our chart. Since we are just creating prototypes, we will set the width of our div inline, as shown in the following code.<div id="firstChart" style="width:600px"></div>
plot
variable. Then, we pass the id
attribute of the div, which is firstChart
. Finally, we include an array of numbers inside another array, which will be our data points. This is the simplest way to pass in the data:<script> $(document).ready(function(){ var plot = $.jqplot ('firstChart', [[1,9,4,3,8,5]]); }); </script> </body> </html>
jqPlot will interpret each number as a point on the y axis, and it will assign a value for the x axis, starting with 1
. We can see the result of our effort in the following screenshot:
3.144.228.78