使用ArcGIS API for Silverlight + Visifire繪制地圖統計圖


   最近把很久之前做的統計圖又拿出來重新做了一遍,感覺很多時候不復習,不記錄就真的忘了,時間是最好的稀釋劑,真是這樣。

   恰好有些網友又向我問起,於是稍作記錄,以便自己今后復習和參考。

    本文示例用的版本為:

   Silverlight 5+Visifire 3.6.8+ArcGIS API for Silverlight 3.0+Visual Studio 2010

一、ArcGIS API For Silverlight 繪制統計圖如何實現

      通常的情況我們是將得到的統計圖作為一個ElementLayer添加到地圖中,通過設置ElementLayer的位置,來設置統計圖在地圖上顯示的位置。

      所有繪制統計圖的工作都是由第三方控件:Visifire完成,當然這里你也可以用Silverlight自帶的Chart控件。

     下面說一下Visifire繪圖的設置過程:

     1.1 首先定義一個Chart(可以理解為畫布),並設置相關屬性,例如:

                    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;
                    // 設定標題
                    Title title = new Title();
                    title.Text = "污染物濃度統計圖";
                    chart.Titles.Add(title);

         1.2 定義曲線(柱狀圖,餅狀圖等),如:

                   DataSeries dataSeries = new DataSeries();
// 設置圖表樣式,這里設置為Column表示柱狀圖,還有Pie表示餅狀圖,以及其他圖形等。                    
dataSeries.RenderAs = RenderAs.Column;

          1.3 定義數據點,例如:
             

                    DataPoint dataPoint = new DataPoint();
                    dataPoint.Exploded = true;
                    dataPoint.AxisXLabel = "污染物A";
                    / Set YValue for a DataPoint
                    dataPoint.YValue = 10;

        1.4 將數據點添加到DataSeries中,然后將DataSeries添加到Chart中,例如:

                     dataSeries.DataPoints.Add(dataPoint);
                     chart.Series.Add(dataSeries);


         1.5 定義ElementLayer,設置Evelop(范圍)屬性,將Chart添加到ElementLayer中,例如:

                    ElementLayer chartlayer = new ElementLayer();
                    chartlayer.ID = "統計圖層";
                    chartlayer.Opacity = 0.7;
//g為輸入的統計要素(點,面,線) MapPoint mapPoint
= g.Geometry as ESRI.ArcGIS.Client.Geometry.MapPoint; //設置該參數來控制統計圖顯示的位置 Envelope extent = new Envelope(mapPoint.X, mapPoint.Y , mapPoint.X , mapPoint.Y); ElementLayer.SetEnvelope(chart, extent); chartlayer.Children.Add(chart);

       1.6 最后將ElementLayer添加到地圖圖層中:  

                     Map.Layers.Add(chartlayer);

       這樣就能得到最后的統計圖了:
                                 

 

 

  【示例下載

  示例代碼用法:點擊地圖任意一點,可添加一個Graphic,並輸入相關屬性,然后點擊統計,即可對添加點的屬性進行統計。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM