AnsweredAssumed Answered

getting lost in an array of objects - defining chart X axis

Question asked by schlot on Apr 9, 2014
Latest reply on Apr 10, 2014 by schlot
I have a map service that has multiple years of data in it.  Each layer has a name that ends in the year.  I have some code that is doing an identify for a particular county that returns each year's data.  I'd like to be able to show this information in the form of a chart.  I've got the values from each year stored in an array.   I'd like to have the X axis of my chart to be labeled with the year of the value. 

I've gotten as far as creating my chart, using dojox/charting, but I'm not sure how to format my year data so that it's formatted correctly for the X axis labels.  I think I'm really close, I'm just lost in the creation of my yearList array.

I have an example of defining an X axis manually
              labels: [{value: 1, text: "Jan"}, {value: 2, text: "Feb"},         {value: 3, text: "Mar"}, {value: 4, text: "Apr"},         {value: 5, text: "May"}, {value: 6, text: "Jun"},         {value: 7, text: "Jul"} 


But I need to do this programmatically since I have different categories of information and they don't all have the same years provided.  I want to be able to build this array from my information, something like this, which is actually the results handler of my identifyTask.  I'm getting lost in how I need to populate the yearList array. The chart draws, but it doesn't like the definition of my X axis labels, so it's still the generate 1, 2, 3, etc.

   function getStatsHandler (results){         stats.length = 0;         yearList.length = 0;         rateList.length = 0;         var year;         for (i=0;i<results.length;i++) {           var lyrResult = results[i];           itemLength = lyrResult.layerName.length;           yearPos = itemLength - 4;           year = lyrResult.layerName.substr(yearPos, 4);//this works because the last 4 characters in the name are always the year             var rate = lyrResult.feature.attributes.RATE;              yearList.push({value: i+1, text:year});             rateList.push(parseFloat(rate));  };        console.log(rateList);     var chart = new Chart2D("chartDiv", {       title: title + " - " + registry.byId("countySelect").value,       titlePos:"bottom",       titleGap: 15            }); chart.addPlot("default", {type: "Lines", hAxis: "x", vAxis: "y"}); chart.addAxis("x", {labels: yearList}); chart.addAxis("y", { vertical: true});     chart.addSeries("Series 1", rateList, {         stroke: { color: "red", width: 2 }     } );     chart.render();    }

Outcomes