GIS餅圖、長條圖、堆疊圖顯示 C#

來源:互聯網
上載者:User

      /// <summary>
        /// 柱狀圖
        /// </summary>
        /// <param name="rs"></param>
        private void WriteHist(GISInfo rs)
        {
            try
            {
                loadXml.Load(rs.GISType, LayerPoint(rs.Stations[0]));
                int countPoint = rs.Stations.Count;
                int countValue = rs.value.Count;

 

                // 定義柱狀圖渲染組件對象
                IChartRenderer pChartRenderer = new ChartRendererClass();
                // 定義渲染欄位對象並給欄位對象執行個體化為pChartRenderer
                IRendererFields pRendererFields = (IRendererFields)pChartRenderer;
                // 向渲染欄位對象中添加欄位
                pRendererFields.AddField("PointID", "PointID");
                if(rs.GISType=="6")
                pRendererFields.AddField("LineID", "LineID");
            
                // 擷取當前圖層,並把它設定成IGeoFeatureLayer的執行個體
                ILayer pLayer = GisMapShow.get_Layer(loadXml.sLayerID);
             
                pLayer.Visible = true;
                IFeatureLayer pFeatLayer = (IFeatureLayer)pLayer;
                IGeoFeatureLayer pGeoFeatLayer = (IGeoFeatureLayer)pLayer;
                IFeatureClass pFeatClass = pFeatLayer.FeatureClass;
             

                // 定義並設定渲染時的chart marker symbol
                IBarChartSymbol pBarChartSymbol = new BarChartSymbolClass();
                pBarChartSymbol.Width = 6;

                IChartSymbol pChartSymbol;
                pChartSymbol = (IChartSymbol)pBarChartSymbol;
                pChartSymbol.MaxValue = 40;  // 設定pChartSymbol的最大值

                IMarkerSymbol pMarkerSymbol;
                pMarkerSymbol = (IMarkerSymbol)pBarChartSymbol;
                pMarkerSymbol.Size = loadXml.sSize;    // 設定bars的最大高度

              

                // 下面給給一個bar設定符號

                // 定義符號數組
                ISymbolArray pSymbolArray = (ISymbolArray)pBarChartSymbol;

                IFillSymbol pFillSymbol;
                // 添加第一個符號
                pFillSymbol = new SimpleFillSymbolClass();
                pFillSymbol.Color = myColor(loadXml.sColor);
                pSymbolArray.AddSymbol((ISymbol)pFillSymbol);
                if (rs.GISType == "6")
                {
                    // 添加第二個符號
                    pFillSymbol = new SimpleFillSymbolClass();
                    pFillSymbol.Color = myColor(loadXml.sArrowColor);
                    pSymbolArray.AddSymbol((ISymbol)pFillSymbol);
                }
                // 設定背景符號
        
                ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();
                pSimpleFillSymbol.Color = myColor(0);
                pChartRenderer.BaseSymbol = (ISymbol)pSimpleFillSymbol;
             

                // Disable overpoaster讓符號處於圖形中央
                pChartRenderer.UseOverposter = true;
              
                pChartRenderer.ChartSymbol = pChartSymbol;
                pChartRenderer.CreateLegend();

                // 將柱狀圖渲染對象與渲染圖層掛鈎
                IDataExclusion pDataExclusion;
                pDataExclusion = pChartRenderer as IDataExclusion;
            
                pGeoFeatLayer.Renderer = (IFeatureRenderer)pChartRenderer;
             //   this.GisMapShow.ActiveView.Refresh();
            }          
            catch (Exception ex) { Logger.Log("WriteHist" + ex); }
        }
        /// <summary>
        /// 餅狀圖
        /// </summary>
        /// <param name="rs"></param>
        private void WriteRound(GISInfo rs)
        {
            try
            {
                loadXml.Load(rs.GISType, LayerPoint(rs.Stations[0]));

                // 定義圖表渲染器
                IChartRenderer pChartRenderer = new ChartRendererClass();

                // 將屬性欄位添加到渲染器中
                IRendererFields pRendererFields = pChartRenderer as IRendererFields;
                pRendererFields.AddField("PointID", "PointID");
                if (rs.GISType == "6")
                    pRendererFields.AddField("LineID", "LineID");

                // 擷取圖層的ITable介面

                ILayer pLayer = GisMapShow.get_Layer(loadXml.sLayerID);
                pLayer.Visible = true;
                IFeatureLayer pFeatLayer = pLayer as IFeatureLayer;
                IFeatureClass pFeatClass = pFeatLayer.FeatureClass;
                ITable pTable = pFeatClass as ITable;

 

                // 定義表徵圖符號
                IPieChartSymbol pPieChartSymbol;
                pPieChartSymbol = new PieChartSymbolClass();
                pPieChartSymbol.Clockwise = true;
                pPieChartSymbol.UseOutline = true;

                // 定義輪廓線符號
                ILineSymbol pOutline;
                pOutline = new SimpleLineSymbolClass();
                IRgbColor pRgbColor = new RgbColorClass();
                pRgbColor.Red = 100;
                pRgbColor.Green = 205;
                pRgbColor.Blue = 30;
                pOutline.Color = pRgbColor;
                pOutline.Width = 2;
                pPieChartSymbol.Outline = pOutline;

                IChartSymbol pChartSymbol;
                pChartSymbol = pPieChartSymbol as IChartSymbol;
                pChartSymbol.MaxValue = 30;
                IMarkerSymbol pMarkerSymbol = pPieChartSymbol as IMarkerSymbol;
                pMarkerSymbol.Size = 30;

                // 設定每個屬性的在餅圖中的符號
                ISymbolArray pSymbolArray = pPieChartSymbol as ISymbolArray;
                ISimpleFillSymbol pFillSymbol;
                pFillSymbol = new SimpleFillSymbolClass();
                pRgbColor = new RgbColorClass();
                pRgbColor.Red = 213;
                pRgbColor.Green = 212;
                pRgbColor.Blue = 252;
                pFillSymbol.Color = pRgbColor;
                pSymbolArray.AddSymbol(pFillSymbol as ISymbol);
                if (rs.GISType == "6")
                {
                    pFillSymbol = new SimpleFillSymbolClass();
                    pRgbColor = new RgbColorClass();
                    pRgbColor.Red = 193;
                    pRgbColor.Green = 252;
                    pRgbColor.Blue = 179;
                    pFillSymbol.Color = pRgbColor;
                    pSymbolArray.AddSymbol(pFillSymbol as ISymbol);
                }
                // 將餅圖符號賦給渲染器
                pChartRenderer.ChartSymbol = (IChartSymbol)pPieChartSymbol;
                pChartRenderer.Label = "Population";

                pChartRenderer.UseOverposter = true;

                IPieChartRenderer pPieChartRenderer;
                pPieChartRenderer = pChartRenderer as IPieChartRenderer;
                pPieChartRenderer.MinSize = loadXml.sArrowSize;

                // 設定最小值,用於尺寸比例
                pPieChartRenderer.MinValue = 453588;
                pPieChartRenderer.FlanneryCompensation = false;
                pPieChartRenderer.ProportionalBySum = true;

                // 產生圖例對象
                pChartRenderer.CreateLegend();

                // 更新圖層的渲染器
                IGeoFeatureLayer pGeoFeatureLayer;
                pGeoFeatureLayer = pLayer as IGeoFeatureLayer;
                pGeoFeatureLayer.Renderer = pChartRenderer as IFeatureRenderer;
                //  axMapControl1.ActiveView.Refresh();
            }
            catch (Exception ex) { Logger.Log("WriteRound:" + ex); }
        }
        /// <summary>
        /// 堆疊圖
        /// </summary>
        private void WriteStack(GISInfo rs)
        {
            try
            {
                loadXml.Load(rs.GISType, LayerPoint(rs.Stations[0]));

                // 定義柱狀圖渲染組件對象
                IChartRenderer pChartRenderer = new ChartRendererClass();
                // 定義渲染欄位對象並給欄位對象執行個體化為pChartRenderer
                IRendererFields pRendererFields = (IRendererFields)pChartRenderer;
                // 向渲染欄位對象中添加欄位
                pRendererFields.AddField("PointID", "PointID");
                if (rs.GISType == "6")               
                    pRendererFields.AddField("LineID", "LineID");
               
                // 擷取當前圖層,並把它設定成IGeoFeatureLayer的執行個體
                ILayer pLayer = GisMapShow.get_Layer(loadXml.sLayerID);
                GisMapShow.get_Layer(loadXml.sLayerID).Visible = true;
                IFeatureLayer pFeatLayer = (IFeatureLayer)pLayer;
                IGeoFeatureLayer pGeoFeatLayer = (IGeoFeatureLayer)pLayer;
                IFeatureClass pFeatClass = pFeatLayer.FeatureClass;

                IStackedChartSymbol pStackedChartSymbol = new StackedChartSymbolClass();
                pStackedChartSymbol.Width = 6;

                IChartSymbol pChartSymbol;
                //pChartSymbol = (IChartSymbol)pBarChartSymbol;
                pChartSymbol = (IChartSymbol)pStackedChartSymbol;

                IMarkerSymbol pMarkerSymbol;
                //pMarkerSymbol = (IMarkerSymbol)pBarChartSymbol;
                pMarkerSymbol = (IMarkerSymbol)pStackedChartSymbol;

                IFillSymbol pFillSymbol;
                // 設定pChartSymbol的最大值
                pChartSymbol.MaxValue = 80;
                // 設定bars的最大高度
                pMarkerSymbol.Size = loadXml.sSize;
                // 下面給給一個bar設定符號

                // 定義符號數組
                //ISymbolArray pSymbolArray = (ISymbolArray)pBarChartSymbol;
                ISymbolArray pSymbolArray = (ISymbolArray)pStackedChartSymbol;

                // 添加第一個符號
                pFillSymbol = new SimpleFillSymbolClass();              
                pFillSymbol.Color = myColor(loadXml.sColor);
                pSymbolArray.AddSymbol((ISymbol)pFillSymbol);
                if (rs.GISType == "6")
                {
                    // 添加第二個符號
                    pFillSymbol = new SimpleFillSymbolClass();
                 
                    pFillSymbol.Color = myColor(loadXml.sArrowColor);
                    pSymbolArray.AddSymbol((ISymbol)pFillSymbol);
                }
            

        
                pChartRenderer.UseOverposter = true;// Disable overpoaster讓符號處於圖形中央
                pChartRenderer.ChartSymbol = pChartSymbol;

                pChartRenderer.CreateLegend();

                // 將柱狀圖渲染對象與渲染圖層掛鈎
                pGeoFeatLayer.Renderer = (IFeatureRenderer)pChartRenderer;
             
            }
            catch (Exception ex) { Logger.Log("WriteStack:" + ex); }
        }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.