Recently, I took out the Statistical Chart I made a long time ago and re-wrote it. I feel that I did not review it many times and forgot it if I did not record it. Time is the best thinner.
Some netizens asked me again, so I made a little record for my future review and reference.
The version used in this example is:
Silverlight 5 + visifire 3.6.8 + ArcGIS API for Silverlight 3.0 + Visual Studio 2010
1. How to Create a Statistical Chart using ArcGIS API for Silverlight
Generally, we add the Statistical Chart to the map as an elementlayer. By setting the location of the elementlayer, we can set the position of the statistical chart displayed on the map.
All the work of drawing statistical charts is done by a third-party control: visifire. Of course, you can also use the chart control that comes with Silverlight here.
The following describes how to set a visifire drawing:
1.1 first define a chart (which can be understood as a canvas) and set relevant attributes, for example:
Chart chart = new chart (); chart. background = NULL; chart. borderbrush = NULL; chart. indicatorenabled = false; chart. lightingenabled = false; chart. view3d = true; chart. height = 300; chart. width = 100; // set the Title = new title (); title. TEXT = "Pollutant Concentration Statistical Chart"; chart. titles. add (title );
1.2 define curves (bar charts, pie charts, etc.), such:
Dataseries = new dataseries (); // set the chart style. column indicates the column chart, pie indicates the pie chart, and other charts.
Dataseries. renderas = renderas. column;
1.3 define data points, for example:
Datapoint = new datapoint (); datapoint. Exploded = true; datapoint. axisxlabel = "Pollutant a";/set yvalue for a datapoint. yvalue = 10;
1.4 add data points to dataseries and add dataseries to chart. For example:
dataSeries.DataPoints.Add(dataPoint); chart.Series.Add(dataSeries);
1.5 define elementlayer, set the evelop (range) attribute, and add the chart to elementlayer. For example:
Elementlayer chartlayer = new elementlayer (); chartlayer. ID = "Statistical layer"; chartlayer. Opacity = 0.7;
// G is the input statistical element (point, surface, line) mappoint = G. geometry as ESRI. arcGIS. client. geometry. mappoint; // set this parameter to control the position of the Statistical Chart. Envelope extent = new envelope (mappoint. x, mappoint. y, mappoint. x, mappoint. y); elementlayer. setenvelope (chart, extent); chartlayer. children. add (Chart );
1.6 Add elementlayer to the map layer:
Map.Layers.Add(chartlayer);
In this way, we can get the final statistical chart:
[Sample download]
Sample Code usage: Click any point on the map to add a graphic, enter relevant attributes, and click statistics to collect statistics on the attributes of the added vertex.