Select to view content in your preferred language

Does "null" value matters when using Class Break Renderer?

2237
2
11-08-2012 07:54 AM
LuhuaCai
Emerging Contributor
Hi, all

I am working on an application similar to the equal interval break demo at: http://help.arcgis.com/en/webapi/javascript/arcgis/samples/renderer_equal_interval/index.html. I was able to get the break value but not able to add the breaks to the renderer.  I can only get the default symbols to show on my map.

The attribute field I am working with contains some null values.Could that be the problem?

here is the code of the rendering function.

Any ideas? thanks.

Lu

 function initOperationalLayer() {
          featureLayer = new esri.layers.FeatureLayer("http://..../MapServer/0", {
          mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,
          outFields: ["*"],
          id:"city_expense"
        });
        
         var query = new esri.tasks.Query();
         query.where = "1=1";
         featureLayer.queryFeatures(query, function(featureSet) {
              
          var features = featureSet.features;
          var min = max = parseFloat(features[0].attributes['sqldb27.SDE.afr_2010.publicSafety_e']);
           
          dojo.forEach(features, function(feature) {
            min = Math.min(min, feature.attributes['sqldb27.SDE.afr_2010.publicSafety_e']);
            max = Math.max(max, feature.attributes['sqldb27.SDE.afr_2010.publicSafety_e']);
          });
          
          //divide the range of values by the number of classes to find the interval
          var numRanges = dijit.byId("breakLevel").get('displayedValue');
          var breaks = (max - min) / numRanges;
          var outline = new esri.symbol.SimpleLineSymbol().setWidth(1);
          var fillColor = new dojo.Color([240, 150, 240, 0.75]);
          var defaultSymbol = new esri.symbol.SimpleMarkerSymbol().setSize(2).setOutline(outline);

          var renderer = new esri.renderer.ClassBreaksRenderer(defaultSymbol, 'sqldb27.SDE.afr_2010.publicSafety_e');

          //add the breaks using the interval calculated above
          for (var i = 0; i < numRanges; i++) {
            renderer.addBreak(parseFloat(min + (i * breaks)), parseFloat(min + ((i + 1) * breaks)), new esri.symbol.SimpleMarkerSymbol().setSize((i + 1) * 4).setColor(fillColor).setOutline(outline));
          }
          featureLayer.setRenderer(renderer);
        });
  
        map.addLayers(featureLayer);
      }
0 Kudos
2 Replies
by Anonymous User
Not applicable

Hi Lu - did you ever find a solution to this?

0 Kudos
YueWu1
by Esri Regular Contributor
Esri Regular Contributor

Hi Luhua,

That might be a problem if you have some null value, take a look about this documentation ClassBreaksRenderer | API Reference | ArcGIS API for JavaScript

You can set some breakpoint in code to debug if that's the issue.

Also, you can try to follow another sample to addBreak manually to compare Class breaks renderer | ArcGIS API for JavaScript

0 Kudos