javascriptgoogle-maps-api-3dom-eventsgoogle-fusion-tables

Reduce recursion in Javascript, Fusion Tables API


The values in the x-axis keep on recurring and I want only three values to appear: Rural, Peri Urban and Urban. Below is my Javascript code showing the drawChart function used to visualize the chart. What could be the problem?

     function drawVisualization(County) {
    google.visualization.drawChart({
      containerId: "visualization",
      dataSourceUrl: "http://www.google.com/fusiontables/gvizdata?tq=",
      query: "SELECT Environment,'BoyPupils','GirlPupils' " +
          "FROM 1eC4sIAgVXfFj01mOM2cDiyW2nly7TcFeIXj1G3s" +
          "WHERE Environment IN ('Rural','Urban'.'Peri Urban')",
      chartType: "ColumnChart",
      options: {
        title: County,
        height: 750,
        width: 1100
      }
    });
  }

I want only three values to appear unlike in the image


Solution

  • You need a GROUP BY clause for Environment and must use SUM for the other columns

    "SELECT Environment, \
              SUM('BoyPupils') as BoyPupils, \
              SUM('GirlPupils') as GirlPupils \
           FROM 1eC4sIAgVXfFj01mOM2cDiyW2nly7TcFeIXj1G3s \
           GROUP BY Environment"
    

    http://jsfiddle.net/doktormolle/L6Yqp/