Dundas Data Visualization Support Site
Dundas Support Site Home  |  Contact Us  |  Dundas Home  
Contact Us via Email
Home

How do I show only some elements in the legend or color swatch panel?

 

Q. How do I show only some elements in the legend or color swatch panel?

A. When the ShowInLegend or ShowInColorSwatch property is set on your shape, path, symbol or group rule, the elements and their colors generated by the rule are automatically added to the legend's Items collection or to the color swatch panel. If you have a lot of elements, and the rule's field property is set to "(Name)", this can be a problem.

If you want only some elements to display in the legend, set the Category property of your rule and your elements. In the example above, we set a select few shapes' Category property to "ShowInLegend", and set the Category property of our shape rule to the same. This is easiest at design-time, but here is some code that sets this at run-time as an example:

[C#]
MapControl1.Shapes["Australia"].Category = "ShowInLegend";
MapControl1.ShapeRules[0].Category = "ShowInLegend";
[VB.NET]
MapControl1.Shapes("Australia").Category = "ShowInLegend"
MapControl1.ShapeRules(0).Category = "ShowInLegend"

If you want the remaining elements to have colors automatically applied, add a second rule without the Category property set. The resulting map is much less cramped:

PoorExcellent