麻辣GIS微信平台

更多 GIS 干货

微信关注不错过

ArcGIS Engine 10 开发手册(7-13)ArcGIS Engine中柱状图的调用

本文介绍使用ArcGIS Engine生成柱状图的方法。

ArcGIS Engine生成柱状图示例代码

代码如下:

class BarRender

{

  public BarRender (AxMapControl pMapcontrol, IFeatureLayer pFtLayer, String pFieldName1, string pFieldName2)

  {

    IGeoFeatureLayer pGeoFeatureLayer = pFtLayer as IGeoFeatureLayer;
    pGeoFeatureLayer.ScaleSymbols = true;

    IFeatureClass pFeatureClass = pFtLayer.FeatureClass;

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

    IChartRenderer pChartRenderer = new ChartRendererClass ();

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

    pRendererFields = (IRendererFields) pChartRenderer;

    //向渲染字段对象中添加字段--- 待补充自定义添加 
    pRendererFields.AddField (pFieldName1, pFieldName1);
    pRendererFields.AddField (pFieldName2, pFieldName2);

    ITable pTable = pGeoFeatureLayer as ITable;
    int[] pFieldIndecies = new int[2];

    pFieldIndecies[0] = pTable.FindField (pFieldName1);
    pFieldIndecies[1] = pTable.FindField (pFieldName2);

    IDataStatistics pDataStat = new DataStatisticsClass ();

    IFeatureCursor pFtCursor = pFtLayer.FeatureClass.Search (null, false);
    pDataStat.Cursor = pFtCursor as ICursor;

    pDataStat.Field = pFieldName2;

    double pMax = pDataStat.Statistics.Maximum;

    // 定义并设置渲染时用的chart marker symbol

    IBarChartSymbol pBarChartSymbol = new BarChartSymbolClass ();
    pBarChartSymbol.Width = 6;

    IChartSymbol pChartSymbol;

    pChartSymbol = pBarChartSymbol as IChartSymbol;

    IMarkerSymbol pMarkerSymbol;

    pMarkerSymbol = (IMarkerSymbol) pBarChartSymbol;

    IFillSymbol pFillSymbol;

    //设置pChartSymbol的最大值 
    pChartSymbol.MaxValue = pMax;

    // 设置bars的最大高度

    pMarkerSymbol.Size = 80;

    //下面给每一个bar设置符号

    //定义符号数组

    ISymbolArray pSymbolArray = (ISymbolArray) pBarChartSymbol;

    //添加第一个符号

    pFillSymbol = new SimpleFillSymbolClass ();
    pFillSymbol.Color = GetRGBColor (193, 252, 179) as IColor;
    pSymbolArray.AddSymbol (pFillSymbol as ISymbol);

    //添加第二个符号

    pFillSymbol = new SimpleFillSymbolClass ();
    pFillSymbol.Color = GetRGBColor (145, 55, 251) as IColor;
    pSymbolArray.AddSymbol (pFillSymbol as ISymbol);

    pChartRenderer.ChartSymbol = pChartSymbol as IChartSymbol;

    //pChartRenderer.Label = "AREA"; 
    pFillSymbol = new SimpleFillSymbolClass();

    pFillSymbol.Color = GetRGBColor (239, 228, 190);
    pChartRenderer.BaseSymbol = (ISymbol) pFillSymbol;
    pChartRenderer.CreateLegend ();

    pChartRenderer.UseOverposter = false;

    //将柱状图渲染对象与渲染图层挂钩

    pGeoFeatureLayer.Renderer = (IFeatureRenderer) pChartRenderer;

    null);

}

//刷新地图和TOOCotrol

IActiveView pActiveView = pMapcontrol.ActiveView as IActiveView;
pActiveView.PartialRefresh (esriViewDrawPhase.esriViewGeography, null,

  public IRgbColor GetRGBColor (int r, int g, int b)

  {

    IRgbColor pRGB;

    pRGB = new RgbColorClass ();

    pRGB.Red = r;
    pRGB.Green = g;
    pRGB.Blue = b;
    return pRGB;

  }

}

效果如图

如果注释掉下面的几句代码,看到的效果如下:

//pFillSymbol = new SimpleFillSymbolClass();

//pFillSymbol.Color = GetRGBColor(239, 228, 190);

//pChartRenderer.BaseSymbol = (ISymbol)pFillSymbol;

ArcGIS Engine 10 开发手册全集

ArcGIS Engine 10 开发手册全集: ArcGIS Engine 10 开发手册

相关阅读

麻辣GIS-Sailor

作者:

GIS爱好者,学GIS,更爱玩GIS。

声明

1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。

2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。

手机阅读
公众号关注
知识星球
手机阅读
麻辣GIS微信公众号关注
最新GIS干货
关注麻辣GIS知识星球
私享圈子

留言板(小编看到第一时间回复)