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

如果本文对你有所帮助,欢迎对我们团队进行打赏捐助,让我们在传播3S的路上可以走得更远。
赞赏支持
微信捐助麻辣GIS 支付宝捐助麻辣GIS

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

如您有疑问,可在文末留言,也可在 麻辣GIS•小分队 搜索回答或发帖 ,还可以在QQ群中提问。

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

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

本站QQ群(三):627853279 麻辣GIS(三)

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

发表评论