Blog2011 ≫ Graph fun

Have just written some code to make a graph for work. Actually written the code that writes some code, as I'm using Google's interactive chart API1 to make some graphs of my data, so have written some code that then outputs this script, that Google then turns in to a graph. I like it!

  google.load( 'visualization', '1.0', { packages: [ 'corechart' ] } );
  google.setOnLoadCallback( function () {
    var data = google.visualization.arrayToDataTable( [
      [ 'Date', 'Hit', 'Miss', 'Rate %' ],
      ["2011-10-06",1523043,3257565,68],
      ["2011-10-07",141,318,69],
      ["2011-10-08",0,0,0],
      ["2011-10-09",0,0,0],
      ["2011-10-10",1691122,5285465,75],
      ["2011-10-11",2561827,6440954,71],
      ["2011-10-12",2489872,6102828,71],
      ["2011-10-13",1336691,2662614,66]
    ] );
    var chart = new google.visualization.ComboChart( document.getElementById( 'chart_div' ));
    chart.draw( data, {
      seriesType: 'bars',
      width: '100%',
      height: 400,
      isStacked: true,
      series: {
        2: {
          type: 'line',
          targetAxisIndex: 1
        }
      },
      vAxes: [
        {
          title: 'Actual hits and misses',
        },
        {
          title: 'Hit rate %',
          maxValue: 100
        }
      ]
    } );
  } );

then the graph itself looks something like this

Next stop find some reason to use the gauge chart2 style, it looks great.

⬅️ :: ➡️

Paul Clarke's weblog - I live in A small town, Kent. Wed + father to two, I am a full-stack web engineer, + I do javascript / Node, some ruby, python, php ect ect. I like pubs, running, eating, home automation + other diy jiggery-pokery, history, family tree stuff, TV, squirrels, pirates, lego, + TIME TRAVEL.