Use your left/right keys to browse tutorials
Using Highcharts JavaScript Library

Using Highcharts JavaScript Library

1 Star2 Stars3 Stars4 Stars5 Stars
Posted on January 12, 2010

There are some great JavaScript graph libraries out there and one that’s recently come to my attention is which is compatible with both the jQuery and Mootools frameworks. To get started point your browser here where you can download all the files you need including examples. Highcharts features include slick tooltips to reference points on your charts, it’s compatible with all standard web browsers, the setup for a graph as demonstrated below is simple and uses the JSON data type, there are also multiple types of graph type, from line, spline, area, areaspline, column, bar, pie and scatter chart.


The Code

Here’s how to setup a simple chart. you need to include the jQuery framework as well as the highcharts.js file and excanvas.js file for IE users which you’ll get in the download from Highcharts. once you’ve got that setup simply paste this into your document head, and create a div with the id ‘graphDiv’, this is where the graph will render to. Note in the first few lines of setup code at the top of the script we specify this along with the chart type. In this case we’re using a bar chart. Below that we have the setup title parameter which is the main label for the graph along with the labels for the x and y axis.

You should be left with a graph as shown below.

HighCharts Fruit Chart

   $(document).ready(function() {
      var chart1 = new Highcharts.Chart({
         chart: {
            renderTo: 'graphDiv',
            defaultSeriesType: 'bar'
         title: {
            text: 'Fruit Consumption'
         xAxis: {
            categories: ['Apples', 'Bananas', 'Oranges']
         yAxis: {
            title: {
               text: 'Fruit eaten'
         series: [{
            name: 'Anne',
            data: [1, 0, 4]
         }, {
            name: 'Martin',
            data: [5, 7, 3]

NOTE: the demo below is not of the code above. If you want to play around with the code for the demo you can simply copy the source from your web browser whilst viewing the demo


More tutorials from Papermashup
  • Magda

    Hi Ashley, I would request if you could send me the php sample code to read from psql (mysql). I will greatly appreciate. thanks