Select to view content in your preferred language

Set number of decimals in toc when using class breaks renderer

204
2
Jump to solution
06-07-2024 12:51 AM
MariusN
New Contributor II

Is there a way to define the number of decimals/format of the labels in the toc when using the class breaks renderer (GraduatedColorsRendererDefinition). 

And,, if the field used for the renderer is empty. show a diferent output in the toc.

           GraduatedColorsRendererDefinition gcDef = new GraduatedColorsRendererDefinition()
           {
               ClassificationField = "xxx",
               ClassificationMethod = ClassificationMethod.NaturalBreaks,
               BreakCount = 5,
               ColorRamp = colorRamp,

               ExclusionClause = $"{xxx} IS Null Or {xxx} = 0",
               ExclusionSymbol = emptySymbol,
               ExclusionLabel = "No value",
           };



No values shows :

MariusN_0-1717759413522.png

 

 

1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

@MariusN 

You can use the CIMNumericFormat to format the labels on the renderer. Once your modify the renderer with this format, call the RecalculateRenderer method to update the renderer with your format. Pass in "false" to this method so that it does not regenerate the values for the class breaks. Here is a code snippet

 

GraduatedColorsRendererDefinition gcDef = new GraduatedColorsRendererDefinition()
{
  ClassificationField = "POP2000",
  ClassificationMethod = ClassificationMethod.NaturalBreaks,
  BreakCount = 5,
  ColorRamp = GetColorRamp()
  
};
CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(gcDef);

var numberFormat = new CIMNumericFormat
{
  RoundingValue = 4,
  RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfDecimals,
  ZeroPad = false
};
renderer.NumberFormat = numberFormat;
featureLayer?.SetRenderer(renderer);
featureLayer?.RecalculateRenderer(false);

View solution in original post

0 Kudos
2 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

The best way to solve questions like yours is to use CIMViewer.

Compile code, run ArcGIS Pro. Open CIMVIewr and select your layer. All settings you will find in CIMViewer. XML tags are same as objects and properties names.

GKmieliauskas_0-1718004572859.png

In your case you need to set up Label Property of CIMClassBreak .

How to work with CIMClassRenderer you can find in ArcGIS Pro community sample GetSymbolSwatch sample 

0 Kudos
UmaHarano
Esri Regular Contributor

@MariusN 

You can use the CIMNumericFormat to format the labels on the renderer. Once your modify the renderer with this format, call the RecalculateRenderer method to update the renderer with your format. Pass in "false" to this method so that it does not regenerate the values for the class breaks. Here is a code snippet

 

GraduatedColorsRendererDefinition gcDef = new GraduatedColorsRendererDefinition()
{
  ClassificationField = "POP2000",
  ClassificationMethod = ClassificationMethod.NaturalBreaks,
  BreakCount = 5,
  ColorRamp = GetColorRamp()
  
};
CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(gcDef);

var numberFormat = new CIMNumericFormat
{
  RoundingValue = 4,
  RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfDecimals,
  ZeroPad = false
};
renderer.NumberFormat = numberFormat;
featureLayer?.SetRenderer(renderer);
featureLayer?.RecalculateRenderer(false);
0 Kudos