title: Using AmCharts to create bar chart from JSON object retrieved from localStorage
body: <p>I'm trying to create a bar chart using AmCharts using an array that is part of a larger JSON object that is being retrieved from localStorage.  Basically, what I do is retrieve the JSON string, parse it back to JSON object, search take the specific array I'm dealing with ("results"), search that array for the result I'm looking for (via "id"), and then take the array I need ("scores") from that specific result.  Then, I use that array as the input for the AmChart code.</p>
  
  <p>I've tested the AmChart code with another sample array (defined in the code) and it works fine.  However, when I try to retrieve from localStorage, I am unable to get the chart to display.  Any thoughts as to why?  The code in question is here:</p>
  
  <pre><code>//retrieve initial results response from localstorage 
  var search_results = localStorage.getItem("results_response"); 
  
  //convert retrieved string back to JSON array 
  var search_results_object = JSON.parse(search_results); //search_results_objects is now a JSON array 
  
  var results = search_results_object.results; //pull out results array 
  
  //get venue_id of detail page from local storage 
  var ven_id = localStorage.getItem("country_id"); 
  
  //search JSON response for venue ID 
  var chartDataResults = []; 
  var searchField = "id"; 
  var searchVal = ven_id; 
  for (var i=0 ; i &lt; results.length ; i++) 
  { 
  if (results[i][searchField] == searchVal) { 
      chartDataResults.push(results[i]); 
  } 
  }  
  
  var chartDataInput = chartDataResults.scores; 
  
  //this all works:
  var chartData = chartDataInput; 
  
  var chart = new AmCharts.AmSerialChart(); 
  chart.dataProvider = chartData; 
  chart.categoryField = "country"; 
  chart.rotate = true; 
  
  var graph = new AmCharts.AmGraph(); 
  graph.valueField = "score"; 
  graph.type = "column"; 
  chart.addGraph(graph); 
  
  var categoryAxis = chart.categoryAxis; 
  categoryAxis.autoGridCount = false; 
  categoryAxis.gridCount = chartData.length; 
  categoryAxis.gridPosition = "start"; 
  categoryAxis.labelRotation = 90; 
  graph.fillAlphas = 0.8; 
  chart.write('chartdiv'); 
  </code></pre>
  
  <p>Most recently, the dev console in Chrome has told me "Uncaught TypeError: Cannot read property 'length' of undefined".  The chart does not render, either.  Thoughts?  I appreciate any and all help.</p>