windowsforms-17682-controls-and-libraries-map-control-getting-started-lesson-3-add-analytical-data-to-a-geographical-map.md
The Map control can visualize data bound to geographical coordinates from various data sources (a database, an XML file, a list of records, etc.). This tutorial describes the steps required to create Pie charts on the map surface using data stored in an external XML file. This XML data file contains Olympic Games medal information.
To bind a map control to an XML data source, follow the instructions below:
Add an empty VectorItemsLayer to the Map’s MapControl.Layers collection as follows:
To bind a data source to this layer, run the Data Source Wizard , as shown in the following image:
On the first Data Source Configuration Wizard page, set a data adapter as PieChartDataAdapter that allows the vector layer to generate Pie chart items. Then, click Next.
In the list of available technologies, select the XML Data item. Then, click Next.
On the next page, select the Loading a DataSet from XML item. Then, click Next.
On the final Data Source Configuration Wizard page, do the following:
To create Pie chart items on the map surface, invoke the Map’s Layers Editor as shown below.
In the editor, customize the ChartDataSourceAdapter.MeasureRules property to specify how chart items are ranged by their values. To do this, assign a MeasureRules object to the property and specify the MeasureRules.RangeStops property of this object as shown below.
Modify the minimum and maximum sizes of pie charts. For this, set ChartDataSourceAdapter.ItemMinSize to 20 and ChartDataSourceAdapter.ItemMaxSize to 60.
Specify the MapItemsLayerBase.ToolTipPattern property as follows:
Finally, handle the layer’s LayerBase.DataLoaded event.
The next step is the Colorizer customization. For this, do the following:
In the Layers Editor , assign a KeyColorColorizer object to the VectorItemsLayer.Colorizer property.
Specify the KeyColorColorizer.ItemKeyProvider property as ArgumentItemKeyProvider.
Add the following Color objects to the KeyColorColorizer.Colors collection:
Add the following key-name pairs to the KeyColorColorizer.Keys collection. Note that the key type should be Int32.
The application should look like this if it is launched now :
To add legends to the application, do the following:
Click the Map control’s smart tag to invoke its Actions list. In the Actions list, click the Edit Legends… link.
In the invoked Legends Editor, choose ColorListLegend and click the Add ColorListLegend button.
Set the MapLegendBase.Header property to Medal Class.
Set the ItemsLayerLegend.Layer property to the vector layer.
Repeat the three previous steps to add a SizeLegend with the Medal Count as the MapLegendBase.Header property value.
Finally, set the MapLegendBase.Alignment property of the SizeLegend object to LegendAlignment.TopRight.
Run the application to see the results.
See Also
How to: Manually Generate Vector Items
How to: Automatically Generate Vector Items from a Datasource
How to: Automatically Generate Bubble Charts Items from a Datasource
How to: Automatically Generate Pie Charts Items from a Datasource