zoukankan      html  css  js  c++  java
  • 制作专题图——柱状图

                //获取当前图层,并把它设置成IGeoFeatureLayer的实例

                IMap pMap = axMapControl1.Map;

                ILayer pLayer = pMap.get_Layer(0) as IFeatureLayer;

                IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;

                IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer;

                pGeoFeatureLayer.ScaleSymbols = false ;

                //获取图层上的feature

                IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;

                //定义柱状图渲染组建对象

                IChartRenderer pChartRenderer = new ChartRendererClass();

                //定义渲染字段对象并给字段对象实例化为pChartRenderer

                IRendererFields pRendererFields;

                pRendererFields = (IRendererFields)pChartRenderer;

               

                //向渲染字段对象中添加字段--- 待补充自定义添加

                pRendererFields.AddField("SHAPE_Area", "SHAPE_Area");

                pRendererFields.AddField("OBJECTID", "OBJECTID");

                // 通过查找features的所用字段的值,计算出数据字段的最大值,作为设置柱状图的比例大小的依据

                ITable pTable;

                int fieldNumber;

                pTable = pFeatureLayer as ITable;

                // 查找出geoFeatureLayer的属性表中的字段个数

                fieldNumber = pTable.FindField("SHAPE_Area");

                if (fieldNumber == -1)

                {

                    MessageBox.Show("Can't find field called ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }

                const int numFields = 2;// 设置bars的个数

                int[] fieldIndecies = new int[2];

                //long fieldIndex;

                double maxValue;

                bool firstValue;

                //double[] fieldValue=new double[5];

                double fieldValue;

                fieldIndecies[0] = pTable.FindField("SHAPE_Area");

                fieldIndecies[1] = pTable.FindField("OBJECTID");

                firstValue = true;

                maxValue = 0;

                int n = pFeatureClass.FeatureCount(null);

                for (int i = 0; i < numFields; i++)

                {

                    IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);

                    for (int j = 0; j < n; j++)

                    {

                        IFeature pFeature = pFeatureCursor.NextFeature();

                        fieldValue = Convert.ToDouble(pFeature.get_Value(fieldIndecies[i]));

                        if (firstValue)

                        {

                            //给maxValue赋初值

                            maxValue = fieldValue;

                            firstValue = false;

                        }

                        else if (fieldValue > maxValue)

                        {

                            maxValue = fieldValue;

                        }

                    }

                }

                if (maxValue <= 0)

                {

                    MessageBox.Show("Failed to calculate the maximum value or maxvalue is 0.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }

                //创建累积排列符号

                IStackedChartSymbol stackedChartSymbol = new StackedChartSymbolClass();

                stackedChartSymbol.Width = 10;

                //stackedChartSymbol.UseOutline = true;

                IMarkerSymbol pMarkerSymbol = stackedChartSymbol as IMarkerSymbol;

                pMarkerSymbol.Size = 50;

                IChartSymbol pChartSymbol = stackedChartSymbol as IChartSymbol;

                pChartSymbol.MaxValue = maxValue;

                //添加渲染符号

                ISymbolArray pSymbolArray = stackedChartSymbol as ISymbolArray;

                IFillSymbol pFillSymbol = new SimpleFillSymbolClass();

                pFillSymbol.Color = getRGB(255, 0, 0);

                pSymbolArray.AddSymbol(pFillSymbol as ISymbol );

                pFillSymbol = new SimpleFillSymbolClass();

                pFillSymbol.Color = getRGB(0, 255, 0);

                pSymbolArray.AddSymbol(pFillSymbol as ISymbol);

                //设置柱状图符号

                pChartRenderer.ChartSymbol = stackedChartSymbol as IChartSymbol;

                pFillSymbol = new SimpleFillSymbolClass();

                pFillSymbol.Color = getRGB(0, 0,255);

                pChartRenderer.BaseSymbol = pFillSymbol as ISymbol;

                pChartRenderer.UseOverposter = false ;

               

                //创建图例

                pChartRenderer.CreateLegend();

                pGeoFeatureLayer.Renderer = pChartRenderer as IFeatureRenderer;

                axMapControl1.Refresh();

  • 相关阅读:
    POJ 2289 Jamie's Contact Groups / UVA 1345 Jamie's Contact Groups / ZOJ 2399 Jamie's Contact Groups / HDU 1699 Jamie's Contact Groups / SCU 1996 Jamie's Contact Groups (二分,二分图匹配)
    HDU 2389 Rain on your Parade / HUST 1164 4 Rain on your Parade(二分图的最大匹配)
    CJOJ 1494 【网络流24题】 搭配飞行员(二分图最大匹配)
    Luogu 1402 酒店之王(二分图最大匹配)
    CJOJ 1943 【重庆八中模拟赛】寻找代表元(二分图最大匹配)
    Luogu 2756 飞行员配对方案问题(二分图最大匹配)
    Luogu 1559 运动员最佳匹配问题(带权二分图最大匹配)
    Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall / POJ 1274 The Perfect Stall(二分图最大匹配)
    Conda和Python的国内安装源
    快速安装Rainbond——开源企业级Paas平台
  • 原文地址:https://www.cnblogs.com/sdustyuleyi/p/2727724.html
Copyright © 2011-2022 走看看