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 开发手册

如您有疑问,可在文末留言,或到QQ群提问。

本站QQ群(一):291616564(满) 麻辣GIS

本站QQ群(二):166408035(新) 麻辣GIS(二)

微信公众号:malagis,扫描右边二维码直接关注。

微信捐助麻辣GIS 支付宝捐助麻辣GIS

如果本文对您有所帮助,欢迎对我们团队进行打赏捐助,让我们在传播3S的路上可以走得更远。


作者:,GIS爱好者。
分享本文,请您带上本文链接

发表评论