Wednesday, November 20, 2013

the "Cannot use 'in' operator to search for 'x'" error and dojox piecharting

SOMEHOW I managed to finally get past the "Cannot use 'in' operator to search for 'x'" error. You do not need to use the x value whatsoever in a dojox pie chart, so I just leave it out below. However, if I put it back in it does not seem to break my code. I had an error somewhere and I no longer know what it is. Er, I guess I never knew. All I knew is it wasn't working. At any rate, I finally have working code now and it follows. If you hit this same heartache, keep fighting! Others have been where you are now.

define([
   "dojo/_base/lang",
   "dojo/_base/declare",
   "dojo/dom",
   "dojox/collections/Dictionary",
   "dojo/dom-style",
   "dojo/data/ItemFileReadStore",
   "dojox/charting/Chart",
   "dojox/charting/themes/Claro",
   "dojox/charting/plot2d/Pie",
   "dojox/charting/DataChart"
], function (
   lang,
   declare,
   dom,
   Dictionary,
   domStyle,
   ItemFileReadStore,
   Chart,
   theme,
   Pie,
   DataChart
) {
   var app;
   return {
      init: function() {
      },
      destroy: function() {
      },
      beforeActivate: function(current, data) {
         chartData = [
            { y: 15, text: "Buchanan" },
            { y: 30, text: "Coolidge" },
            { y: 13, text: "Fillmore" },
            { y: 20, text: "Garfield" },
            { y: 37, text: "Nixon" },
            { y: 11, text: "Polk" },
            { y: 27, text: "Taft" }
         ];
         var pieChart = new Chart("chartNode");
         pieChart.setTheme(theme);
         pieChart.addPlot("default", {
            type: Pie,
            font: "normal normal 11pt Tahoma",
            fontColor: "black",
            labelOffset: -30,
            radius: 80
         });
         pieChart.addSeries("series",chartData);
         pieChart.render();
      }
   };
});

No comments:

Post a Comment