Back to Devexpress

ChoroplethColorizer.ValueProvider Property

windowsforms-devexpress-dot-xtramap-dot-choroplethcolorizer-f6e96d76.md

latest7.9 KB
Original Source

ChoroplethColorizer.ValueProvider Property

Provides values from the data source (Shapefile or KML file) to color map shapes according to data.

Namespace : DevExpress.XtraMap

Assembly : DevExpress.XtraMap.v25.2.dll

NuGet Package : DevExpress.Win.Map

Declaration

csharp
[DefaultValue(null)]
public IColorizerValueProvider ValueProvider { get; set; }
vb
<DefaultValue(Nothing)>
Public Property ValueProvider As IColorizerValueProvider

Property Value

TypeDefaultDescription
IColorizerValueProvidernull

An object that implements the IColorizerValueProvider interface.

|

Remarks

Refer Colorizers for more information about colorizers the Map Control provides.

Example

This example demonstrates how to paint each map contour in a specific color. To accomplish this, it is necessary to create a colorizer (choropleth or graph) and assign it to the VectorItemsLayer.Colorizer property.

For this colorizer, it is necessary to create a ShapeAttributeValueProvider object, specify the name of the shape attribute that contains a value to be colorized to its ShapeAttributeValueProvider.AttributeName property, and assign this value provider to the ChoroplethColorizer.ValueProvider property.

Then, split the entire data into ranges and add the required range stops to the DoubleCollection returned by the ChoroplethColorizer.RangeStops property.

Finally, add the desired set of colors to the GenericColorizerItemCollection<T> that is accessed from the ChoroplethColorizer.ColorItems property. The colorizer automatically associates each color with the specified data ranges.

Note

  • If you wish to display information on what each color means, create a Color Scale legend. To do this, create a ColorScaleLegend object and add it to the MapControl.Legends collection. In this legend, set its ItemsLayerLegend.Layer property to the previously created layer object and adjust other legend properties as required.
  • If you wish copy the shape file to your project, you should also copy the Countries.dbf file.

View Example

csharp
// Create colorizer for the MapLayer.
    MapLayer.Colorizer = CreateColorizer();
private MapColorizer CreateColorizer() {
    // Create a Choropleth colorizer
    ChoroplethColorizer colorizer = new ChoroplethColorizer();

    // Specify colors for the colorizer.
    colorizer.ColorItems.AddRange(new ColorizerColorItem[] {
        new ColorizerColorItem(Color.FromArgb(0x5F, 0x8B, 0x95)), 
        new ColorizerColorItem(Color.FromArgb(0x79, 0x96, 0x89)),
        new ColorizerColorItem(Color.FromArgb(0xA2, 0xA8, 0x75)), 
        new ColorizerColorItem(Color.FromArgb(0xCE, 0xBB, 0x5F)),
        new ColorizerColorItem(Color.FromArgb(0xF2, 0xCB, 0x4E)),
        new ColorizerColorItem(Color.FromArgb(0xF1, 0xC1, 0x49)), 
        new ColorizerColorItem(Color.FromArgb(0xE5, 0xA8, 0x4D)),
        new ColorizerColorItem(Color.FromArgb(0xD6, 0x86, 0x4E)),
        new ColorizerColorItem(Color.FromArgb(0xC5, 0x64, 0x50)), 
        new ColorizerColorItem(Color.FromArgb(0xBA, 0x4D, 0x51))
    });

    // Specify range stops for the colorizer.
    colorizer.RangeStops.AddRange(new double[] { 0, 3000, 10000, 18000, 28000, 
        44000, 82000, 185000, 1000000, 2500000, 15000000 });

    // Specify the attribute that provides data values for the colorizer.
    colorizer.ValueProvider = new ShapeAttributeValueProvider() { AttributeName = "GDP_MD_EST" };

    return colorizer;
}
vb
' Create colorizer for the MapLayer.
    MapLayer.Colorizer = CreateColorizer()
Private Function CreateColorizer() As MapColorizer
    ' Create a Choropleth colorizer
    Dim colorizer As New ChoroplethColorizer()

    ' Specify colors for the colorizer.
    colorizer.ColorItems.AddRange(New ColorizerColorItem() { _
        New ColorizerColorItem(Color.FromArgb(&H5F, &H8B, &H95)), _
        New ColorizerColorItem(Color.FromArgb(&H79, &H96, &H89)), _
        New ColorizerColorItem(Color.FromArgb(&HA2, &HA8, &H75)), _
        New ColorizerColorItem(Color.FromArgb(&HCE, &HBB, &H5F)), _
        New ColorizerColorItem(Color.FromArgb(&HF2, &HCB, &H4E)), _
        New ColorizerColorItem(Color.FromArgb(&HF1, &HC1, &H49)), _
        New ColorizerColorItem(Color.FromArgb(&HE5, &HA8, &H4D)), _
        New ColorizerColorItem(Color.FromArgb(&HD6, &H86, &H4E)), _
        New ColorizerColorItem(Color.FromArgb(&HC5, &H64, &H50)), _
        New ColorizerColorItem(Color.FromArgb(&HBA, &H4D, &H51)) _
    })

    ' Specify range stops for the colorizer.
    colorizer.RangeStops.AddRange(New Double() { 0, 3000, 10000, 18000, 28000, 44000, 82000, 185000, 1000000, 2500000, 15000000 })

    ' Specify the attribute that provides data values for the colorizer.
    colorizer.ValueProvider = New ShapeAttributeValueProvider() With {.AttributeName = "GDP_MD_EST"}

    Return colorizer
End Function

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ValueProvider property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-map-create-choropleth-map-based-on-shapefile/CS/XtraMap_ShapefileDataAdapter/Form1.cs#L67

csharp
// Specify the attribute that provides data values for the colorizer.
colorizer.ValueProvider = new ShapeAttributeValueProvider() { AttributeName = "GDP_MD_EST" };

winforms-map-create-choropleth-map-based-on-shapefile/VB/XtraMap_ShapefileDataAdapter/Form1.vb#L53

vb
' Specify the attribute that provides data values for the colorizer.
colorizer.ValueProvider = New DevExpress.XtraMap.ShapeAttributeValueProvider() With {.AttributeName = "GDP_MD_EST"}
Return colorizer

See Also

ChoroplethColorizer Class

ChoroplethColorizer Members

DevExpress.XtraMap Namespace