title: Grouping / counting in javascript using underscore.js
body: <p>I am new to javascript (and to Stack Overflow) and I've encountered a problem I can't seem to solve. I am trying to generate a simple pie chart that shows the number of Projects for each value of Technology in my data. This is the kind of data I am working with:</p>
  
  <ul>
  <li>[Project1, Java]</li>
  <li>[Project2, Excel]</li>
  <li>[Project3, SAS]</li>
  <li>[Project4, Java]</li>
  </ul>
  
  <p>The pie ratio in the example above would be 2:1:1.</p>
  
  <p>The first part of my code loads the data and pushes it to an array, "techArray", that contains [project, tech]. This part works ok - I've verified it in a simplified version of the code.</p>
  
  <p>I then want to group the array "techArray" and count the instances of each tech. To do so I'm using the Underscore library, as follows:</p>
  
  <pre><code>var chartData = [];
  var techData = _.groupBy(techArray, 'tech');
  _.each(techData, function(row) {
      var techCount = row.length;
      chartData = push( {
          name: row[0].tech,
          y: techCount
      });
  });
  </code></pre>
  
  <p>The script then renders the chartData array using highcharts. Again, I have verified that this section works using a simplified (ungrouped) version.</p>
  
  <p>There must be an issue with the grouping/counting step outlined above because I am seeing no output, but I simply can't find where. I am basing my solution on the following worked example: <a href="http://www.sharepointdeveloperhq.com/2013/05/utilizing-spservices-for-sharepoint-2010-to-create-charts-with-high-charts/" rel="noreferrer">Worked example</a>.</p>
  
  <p>If anyone can spot the error in what I've written, or propose another way of grouping the array, I'd be very grateful. This seems like it should be a simpler task than it's proving to be.</p>