I was specifically trying to get to 2, so leaving the precision parameters out wasn't a solution. The only way I've been able to manipulate the legend the way I wanted was to create it from scratch, making my own rectangles, text etc. I am putting the formatted label string into an array, labelArray, and then pulling them out in the createLegend function. You ought to be able to build a formatLabel function that takes itm.minValue and itm.maxValue as input to format it the way you want before it goes into labelArray. I pretty much had to do this anyway because I wanted a value for "No Data' and the ability to add some extra legend notes.
Continuing with the functions I have earlier, here's the results handler for the generateClassBreaks function. I go on to generate the legend manually.
function applyRenderer(renderer) {
var optionsArray = [];
renderer.defaultSymbol = defaultSymbol;
var drawingOptions = new LayerDrawingOptions();
drawingOptions.renderer = renderer;
optionsArray[0] = drawingOptions;
agLayer.setLayerDrawingOptions(optionsArray);
getInfoFromRender(renderer);//creates arrays the legend will use
createLegend();
}
function getInfoFromRender(renderer){
symbolArray.length = 0;
labelArray.length = 0;
arrayUtils.forEach (renderer.infos, function (itm) {
symbolArray.push(itm.symbol);
var val = itm.minValue + " - " + itm.maxValue;
// labelArray.push(itm.label);
labelArray.push(val);
});
}
// create legend based on symbology defined in code
function createLegend() {
// var divLegend = dom.byId("legendDiv");
domConstruct.empty("legendDiv");
var note = dom.byId('mapHeader').innerHTML;
//change the size of the surface as needed, example: if labels are wider or there are more than 5 intervals
var legendSurface = gfx.createSurface(dom.byId("legendDiv"), 250, 200);
var group = legendSurface.createGroup();
yPos = 20;
var descriptors, legendText;
//symbolArray created as part of the generateRendererTask
arrayUtils.forEach(symbolArray, function (itm, idx){
descriptors = jsonUtils.getShapeDescriptors(itm);
group.createRect({x: 10, y: yPos, width: 30, height: 20 }).
setFill(descriptors.fill).
setStroke(descriptors.stroke);
//labelArray created as part of teh generateRendererTask
legendText = group.createText({ x:45, y:yPos + 15, text:labelArray[idx], align:"start"}).
setFont({ family:"Arial", size:"10pt", weight:"normal" }).
setFill("#000000");
yPos = yPos + 25;
});
// when data value = -999, symbolize as Data Not Available
group.createRect({x: 10, y: yPos, width: 30, height: 20 }).
setFill(jsonUtils.getShapeDescriptors(defaultSymbol).fill).
setStroke(jsonUtils.getShapeDescriptors(defaultSymbol).stroke);
legendText = group.createText({ x:45, y:yPos + 15, text:"Data Not Available", align:"start"}).
setFont({ family:"Arial", size:"10pt", weight:"normal" }).
setFill("#0000");
yPos = yPos + 25;
dom.byId("legendTitle").innerHTML = note +"<br/><i>Percent Total Area Treated</i> " ;
registry.byId('legendPane').set("open", true);
}