麻辣GIS微信平台

更多 GIS 干货

微信关注不错过

ArcGIS Engine 10 开发手册(7-11)ArcGIS Engine中饼图的调用

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

ArcGIS Engine生成饼图示例代码

代码如下:

public PieRender (AxMapControl pMapcontrol, IFeatureLayer pFtLayer, string pFieldName1, string pFieldName2)

{

  IGeoFeatureLayer pGeoFeaLayer = (IGeoFeatureLayer) pFtLayer;

  IChartRenderer pChartRenderer = new ChartRendererClass ();

  // Set up the field to draw charts

  IRendererFields pRenderFields = (IRendererFields) pChartRenderer;
  pRenderFields.AddField (pFieldName1, pFieldName1);
  pRenderFields.AddField (pFieldName2, pFieldName2);

  IPieChartRenderer pPieChartRender = (IPieChartRenderer) pChartRenderer;

  //计算最大值部分有待补充////////////////////////////////////

  //Calculate the max value of the data field to scale the chart

  //ICursor pCursor = new CursorClass(); 
  IQueryFilter pQueryFilter = new QueryFilterClass ();

  //IRowBuffer pRow = new RowBufferClass(); 
  ITable pTable = (ITable) pGeoFeaLayer;
  pQueryFilter.AddField (pFieldName1);

  ICursor pCursor = pTable.Search (pQueryFilter, true);
  IDataStatistics pDataStat = new DataStatisticsClass ();

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

  pDataStat.Field = pFieldName1;

  double pMax = pDataStat.Statistics.Maximum;

  IPieChartSymbol pPiechartSymbol = new PieChartSymbolClass ();
  IFillSymbol pFillSymbol = new SimpleFillSymbolClass ();
  IChartSymbol pChartSymbol = (IChartSymbol) pPiechartSymbol;
  pPiechartSymbol.Clockwise = true;
  pPiechartSymbol.UseOutline = true;

  ILineSymbol pOutLine = new SimpleLineSymbolClass ();
  pOutLine.Color = GetRGBColor (255, 0, 255);
  pOutLine.Width = 1;

  pPiechartSymbol.Outline = pOutLine;

  IMarkerSymbol pMarkerSymbol = (IMarkerSymbol) pPiechartSymbol;

  //finally 
  pChartSymbol.MaxValue = pMax;
  pMarkerSymbol.Size = 16;

  //像符号数组中添加 添加符号

  ISymbolArray pSymbolArray = (ISymbolArray) pPiechartSymbol;
  pFillSymbol.Color = GetRGBColor (213, 212, 252);
  pFillSymbol.Outline = pOutLine;
  pSymbolArray.AddSymbol ((ISymbol) pFillSymbol);

  //////////////////////////

  pFillSymbol.Color = GetRGBColor (183, 242, 122);
  pFillSymbol.Outline = pOutLine;
  pSymbolArray.AddSymbol ((ISymbol) pFillSymbol);

  //set up the background

  pFillSymbol.Color = GetRGBColor (239, 228, 190);
  pChartRenderer.BaseSymbol = (ISymbol) pFillSymbol;
  pChartRenderer.UseOverposter = false;
  pPieChartRender.MinSize = 1;

  pPieChartRender.MinValue = pDataStat.Statistics.Minimum;
  pPieChartRender.FlanneryCompensation = false;
  pPieChartRender.ProportionalBySum = true;
  pChartRenderer.ChartSymbol = (IChartSymbol) pPiechartSymbol;
  pChartRenderer.CreateLegend ();

  pGeoFeaLayer.Renderer = (IFeatureRenderer) pChartRenderer;
  pMapcontrol.ActiveView.Refresh ();

}

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;

}

效果如图

ArcGIS Engine 10 开发手册全集

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


麻辣GIS-Sailor
作者:
GIS爱好者,学GIS,更爱玩GIS。

声明

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

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

3.如果本文对您有所帮助,请您对我们团队进行 打赏捐助让我们在传播3S的路上可以走得更远,不胜感激。PS:如果你是学生党,请优先把经费用于购买学习资料 以及 与小哥哥/小姐姐约会上:-)

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

本站QQ群(一):291616564 加入QQ群

本站QQ群(二):166408035 加入QQ群

本站QQ群(三):627853279 加入QQ群

本站QQ群(四):436386604 加入QQ群

本站QQ群(五):606176554 加入QQ群

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

发表评论