ArcGis Engine 专题地图制图统计图表符号化(柱状图,饼状图)

首先看一下如何在arcgis中制作树状图和饼状图【ArcGIS教程】(95)如何在ArcGIS中制作柱状图与饼状图? - 知乎

Arcgis Engine实现方式:

1.无论是树状图,饼状图,条形图还是堆叠图都是由ChartRenderer类实现的,该类实现IChartRenderer接口。

2.BaseSymbol属性用来设置或返回统计图表的符号。

3.ChartSymbol用来设置或返回统计图表的样式。ChartSymbol可以生成不同的图表,当IChartRenderer的接口ChartSymbol设置为BarChartSymbol PieChartSymbol分别代表壮壮图和饼状图。

4.IChartSymbol中MAxValue设置统计中的最大值

5.ImarkSymbol设置统计图表形状的最大值,柱状图中则表示最大值的最大高度。

实例代码实现思路如下

1.遍历出所选第一个字段的属性值的最大值,并将其赋值给.IChartSymbol中MAxValue,作为统计图大小的依据。

2.根据不同选择生成对应的图表。

效果图:柱状图

ArcGis Engine 专题地图制图统计图表符号化(柱状图,饼状图)_第1张图片

效果图:饼状图

ArcGis Engine 专题地图制图统计图表符号化(柱状图,饼状图)_第2张图片

 代码:

        /// 
        /// 图表
        /// 
        /// 渲染图层
        /// 储存渲染字段和其对应的颜色 
        private void ChartRenderer(IFeatureLayer pFeatLyr, Dictionary dicFieldAndColor)
        {
            IGeoFeatureLayer pGeoFeatLyr = pFeatLyr as IGeoFeatureLayer;
            IChartRenderer pChartRender = new ChartRendererClass();
            IRendererFields pRenderFields = pChartRender as IRendererFields;
            IFeatureCursor pCursor = null;
            IDataStatistics pDataSta = null;
            double dMax = 0; double dTemp = 0;
            IQueryFilter pQueryFilter = new QueryFilterClass();
            pCursor = pGeoFeatLyr.Search(pQueryFilter, true);
            //遍历出所选择的第一个字段的最大值,,作为设置专题图的比例大小的依据
            foreach (KeyValuePair _keyValue in dicFieldAndColor)
            {
                pRenderFields.AddField(_keyValue.Key, _keyValue.Key);
                pDataSta = new DataStatisticsClass();
                pDataSta.Cursor = pCursor as ICursor;
                pDataSta.Field = _keyValue.Key;
                dTemp = pDataSta.Statistics.Maximum;
                if (dTemp >= dMax)
                {
                    dMax = dTemp;
                }
            }

            IRgbColor pRgbColor = null;
            IChartSymbol pChartSym = null;
            IFillSymbol pFillSymbol = null;
            IMarkerSymbol pMarkerSym = null;
            IBarChartSymbol pBarChartSym = null;
            IPieChartSymbol pPieChartSymbol = null;
            IStackedChartSymbol pStackChartSym = null;

            // 定义并设置渲染样式
            switch (_enumChartType)
            {
                case EnumChartRenderType.PieChart:
                    pPieChartSymbol = new PieChartSymbolClass();
                    pPieChartSymbol.Clockwise = true;//说明饼图是否顺时针方向
                    pPieChartSymbol.UseOutline = true;//说明是否使用轮廓线
                    ILineSymbol pLineSym = new SimpleLineSymbolClass();
                    pLineSym.Color = m_OperateMap.GetRgbColor(100, 205, 30) as IColor;
                    pLineSym.Width = 1;
                    pPieChartSymbol.Outline = pLineSym;
                    break;
                case EnumChartRenderType.BarChart:
                    pBarChartSym = new BarChartSymbolClass();
                    pBarChartSym.Width = 6;//设置每个条形图的宽度
                    break;
                case EnumChartRenderType.StackChart:
                    pStackChartSym = new StackedChartSymbolClass();
                    pStackChartSym.Width = 6;//设置每个堆叠图的宽度
                    break;
            }
            if (pPieChartSymbol != null)
            {
                pChartSym = pPieChartSymbol as IChartSymbol;
                pMarkerSym = pPieChartSymbol as IMarkerSymbol;
                pMarkerSym.Size = 30; //设置饼状图的大小
            }
            if (pBarChartSym != null)
            {
                pChartSym = pBarChartSym as IChartSymbol;
                pMarkerSym = pBarChartSym as IMarkerSymbol;
                pMarkerSym.Size = 30;//设置条形图的高度
            }
            else if (pStackChartSym != null)
            {
                pChartSym = pStackChartSym as IChartSymbol;
                pMarkerSym = pStackChartSym as IMarkerSymbol;
                pMarkerSym.Size = 30;//设置堆叠图的高度
            }
            pChartSym.MaxValue = dMax;
            ISymbolArray pSymArray = null;
            if (pBarChartSym != null)
            {
                pSymArray = pBarChartSym as ISymbolArray;
            }
            else if (pStackChartSym != null)
            {
                pSymArray = pStackChartSym as ISymbolArray;
            }
            else if (pPieChartSymbol != null)
            {
                pSymArray = pPieChartSymbol as ISymbolArray;
            }

            foreach (KeyValuePair _keyValue in dicFieldAndColor)
            {
                //获取渲染字段的颜色值
                pRgbColor = _keyValue.Value;
                pFillSymbol = new SimpleFillSymbolClass();
                pFillSymbol.Color = pRgbColor as IColor;
                pSymArray.AddSymbol(pFillSymbol as ISymbol);
            }
            if (pPieChartSymbol != null)
            {
                pChartRender.ChartSymbol = pPieChartSymbol as IChartSymbol;
            }
            if (pBarChartSym != null)
            {
                pChartRender.ChartSymbol = pBarChartSym as IChartSymbol;
            }
            else if (pStackChartSym != null)
            {
                pChartRender.ChartSymbol = pStackChartSym as IChartSymbol;
            }

            pFillSymbol = new SimpleFillSymbolClass();
            pFillSymbol.Color = m_OperateMap.GetRgbColor(239, 228, 190);
            pChartRender.BaseSymbol = pFillSymbol as ISymbol;// 设置背景符号
            //让符号处于图形中央(若渲染的图层为点图层,则该句应去掉,否则不显示渲染结果)
            pChartRender.UseOverposter = false; 
            pChartRender.CreateLegend();

            pGeoFeatLyr.Renderer = pChartRender as IFeatureRenderer;
            mainMapControl.Refresh();           
            mainTOCControl.Update();
            _enumChartType = EnumChartRenderType.UnKnown;
        }

 

 

你可能感兴趣的:(c#,arcgis,arcgisengine)