/// <summary> /// Pie Chart Render /// </summary> /// <param name="currentLayer"></param> /// <param name="breakCount"></param> /// <author>Shen Yongyuan</author> /// <date>20091114</date> public static void PieChartRender(ILayer currentLayer) { //Scale Symbol IGeoFeatureLayer pGeoFeatureL = currentLayer as IGeoFeatureLayer; pGeoFeatureL.ScaleSymbols = true; //Chart Render IChartRenderer pChartRenderer = new ChartRendererClass(); IRendererFields pRendererFields = (IRendererFields)pChartRenderer; pRendererFields.AddField(Town.Constant.Constant.TmpTableIndex + "." + "Ecology", "生态"); pRendererFields.AddField(Town.Constant.Constant.TmpTableIndex + "." + "Social", "社会"); pRendererFields.AddField(Town.Constant.Constant.TmpTableIndex + "." + "Economic", "经济"); //Search Max IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(Town.Constant.Constant.TmpTableIndex + "." + "Ecology"); pQueryFilter.AddField(Town.Constant.Constant.TmpTableIndex + "." + "Social"); pQueryFilter.AddField(Town.Constant.Constant.TmpTableIndex + "." + "Economic"); IFeatureCursor pCursor = pGeoFeatureL.DisplayFeatureClass.Search(pQueryFilter, true); int fldFiledEcology = pCursor.Fields.FindField(Town.Constant.Constant.TmpTableIndex + "." + "Ecology"); int fldFiledSocial = pCursor.Fields.FindField(Town.Constant.Constant.TmpTableIndex + "." + "Social"); int fldFiledEconomic = pCursor.Fields.FindField(Town.Constant.Constant.TmpTableIndex + "." + "Economic"); List <double> valueList = new List <double>(); IFeature pFeature = pCursor.NextFeature(); while (pFeature != null) { valueList.Add(Convert.ToDouble(pFeature.get_Value(fldFiledEcology))); valueList.Add(Convert.ToDouble(pFeature.get_Value(fldFiledSocial))); valueList.Add(Convert.ToDouble(pFeature.get_Value(fldFiledEconomic))); pFeature = pCursor.NextFeature(); } //Pie Chart IPieChartSymbol pPieChartSymbol; pPieChartSymbol = new PieChartSymbolClass(); IChartSymbol pChartSymbol = (IChartSymbol)pPieChartSymbol; //Pie Chart Attribute pPieChartSymbol.Clockwise = true; pPieChartSymbol.UseOutline = true; ILineSymbol pOutline; pOutline = new SimpleLineSymbolClass(); pOutline.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.FromArgb(100, 205, 30)); pOutline.Width = 1; pPieChartSymbol.Outline = pOutline; IMarkerSymbol pMarkerSymbol = (IMarkerSymbol)pPieChartSymbol; pChartSymbol.MaxValue = valueList.Max(); pMarkerSymbol.Size = 60; //Symbol Array ISymbolArray pSymbolArray = (ISymbolArray)pPieChartSymbol; ISimpleFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.Green); pSymbolArray.AddSymbol((ISymbol)pFillSymbol); pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.Red); pSymbolArray.AddSymbol((ISymbol)pFillSymbol); pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.Blue); pSymbolArray.AddSymbol((ISymbol)pFillSymbol); pChartRenderer.ChartSymbol = (IChartSymbol)pPieChartSymbol; pChartRenderer.Label = "指标"; //Back Ground pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.FromArgb(239, 228, 190)); pChartRenderer.BaseSymbol = (ISymbol)pFillSymbol; //Render Label pGeoFeatureL.Renderer = pChartRenderer as IFeatureRenderer; }
//PieChartRenderer圆形分格统计图 private void button7_Click(object sender, EventArgs e) { IGeoFeatureLayer geoFeatureLayer; IFeatureLayer featureLayer; ITable table; ICursor cursor; IRowBuffer rowBuffer; //设置饼图的要素 string field1 = "sqmi"; string field2 = "sqkm"; //获取渲染图层 geoFeatureLayer = getGeoLayer("Continents"); featureLayer = geoFeatureLayer as IFeatureLayer; table = featureLayer as ITable; geoFeatureLayer.ScaleSymbols = true; IChartRenderer chartRenderer = new ChartRendererClass(); IPieChartRenderer pieChartRenderer = chartRenderer as IPieChartRenderer; IRendererFields rendererFields = chartRenderer as IRendererFields; rendererFields.AddField(field1, field1); rendererFields.AddField(field2, field2); int[] fieldIndexs = new int[2]; fieldIndexs[0] = table.FindField(field1); fieldIndexs[1] = table.FindField(field2); //获取渲染要素的最大值 double fieldValue = 0.0, maxValue = 0.0; cursor = table.Search(null, true); rowBuffer = cursor.NextRow(); while (rowBuffer != null) { for (int i = 0; i < 2; i++) { fieldValue = double.Parse(rowBuffer.get_Value(fieldIndexs[i]).ToString()); if (fieldValue > maxValue) { maxValue = fieldValue; } } rowBuffer = cursor.NextRow(); } //设置饼图符号 IPieChartSymbol pieChartSymbol = new PieChartSymbolClass(); pieChartSymbol.Clockwise = true; pieChartSymbol.UseOutline = true; IChartSymbol chartSymbol = pieChartSymbol as IChartSymbol; chartSymbol.MaxValue = maxValue; ILineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = getRGB(255, 0, 0); lineSymbol.Width = 2; pieChartSymbol.Outline = lineSymbol; IMarkerSymbol markerSymbol = pieChartSymbol as IMarkerSymbol; markerSymbol.Size = 30; //添加渲染符号 ISymbolArray symbolArray = pieChartSymbol as ISymbolArray; IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = getRGB(0, 255, 0); symbolArray.AddSymbol(fillSymbol as ISymbol); fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = getRGB(0, 0, 255); symbolArray.AddSymbol(fillSymbol as ISymbol); chartRenderer.ChartSymbol = pieChartSymbol as IChartSymbol; fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = getRGB(100, 100, 100); chartRenderer.BaseSymbol = fillSymbol as ISymbol; chartRenderer.UseOverposter = false; //创建图例 chartRenderer.CreateLegend(); geoFeatureLayer.Renderer = chartRenderer as IFeatureRenderer; this.axMapControl1.Refresh(); }
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 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(); }
private void btnPieChartRender_Click(object sender, EventArgs e) { IGeoFeatureLayer pGeoFeatLyr = this.mainMapControl.get_Layer(0) as IGeoFeatureLayer; //找出两个用于着色字段的最大值的最大值(这次加上最小值之和,这个函数的尾后部分用到,用于在着色对象里确定最小的PieChartSymbol的大小) double p1, p2, max, m1, m2, min; ICursor pCursor = pGeoFeatLyr.Search(null, true) as ICursor; IDataStatistics pDataStatistics = new DataStatisticsClass(); pDataStatistics.Cursor = pCursor; pDataStatistics.Field = "GDP_1994("; p1 = pDataStatistics.Statistics.Maximum; m1 = pDataStatistics.Statistics.Minimum; pCursor = pGeoFeatLyr.Search(null, true) as ICursor; pDataStatistics.Cursor = pCursor; pDataStatistics.Field = "GDP_1999("; p2 = pDataStatistics.Statistics.Maximum; m2 = pDataStatistics.Statistics.Minimum; max = p1 > p2 ? p1 : p2; min = m1 + m2;//最小值之和 //以下生成好三个SimpleFillSymbol,留作后用 ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Color = getRGBColor(255, 0, 0); pSimpleFillSymbol.Outline = null; ISimpleFillSymbol pSimpleFillSymbol2 = new SimpleFillSymbolClass(); pSimpleFillSymbol2.Color = getRGBColor(0, 0, 255); pSimpleFillSymbol2.Outline = null; ISimpleFillSymbol pSimpleFillSymbol3 = new SimpleFillSymbolClass(); pSimpleFillSymbol3.Color = getRGBColor(0, 255, 0); //以下创建并设置PieChartSymbol对象,并设置PieChartSymbol对象的各个SimpleFillSymbol IPieChartSymbol pPieChartSymbol = new PieChartSymbolClass(); pPieChartSymbol.Clockwise = true; pPieChartSymbol.UseOutline = false; IChartSymbol pChartSymbol = pPieChartSymbol as IChartSymbol; pChartSymbol.MaxValue = max; ISymbolArray pSymbolArray = pPieChartSymbol as ISymbolArray; pSymbolArray.AddSymbol((ISymbol)pSimpleFillSymbol); pSymbolArray.AddSymbol((ISymbol)pSimpleFillSymbol2); IMarkerSymbol pMarkerSymbol = pPieChartSymbol as IMarkerSymbol; pMarkerSymbol.Size = 5;//PieChartSymbol的大小(我觉得是饼的厚度) //以下创建并设置着色对象 IChartRenderer pChartRenderer = new ChartRendererClass(); pChartRenderer.BaseSymbol = pSimpleFillSymbol3 as ISymbol; pChartRenderer.ChartSymbol = pChartSymbol; pChartRenderer.UseOverposter = true; pChartRenderer.Label = "GDP"; IPieChartRenderer pPieChartRenderer = pChartRenderer as IPieChartRenderer; pPieChartRenderer.MinSize = 0.5;//最小的尺码关键 pPieChartRenderer.MinValue = 1;//最小尺码的值,为什么0不可以??????????????关键 pPieChartRenderer.ProportionalBySum = true;//PieChartSymbol的大小按照字段和成比例,关键 //若PieChartSymbol的大小只按一个字段,则须设置.ProportionalField为该字段 IRendererFields pRenderFields = pChartRenderer as IRendererFields;//添加用于着色的字段 pRenderFields.AddField("GDP_1994(", "GDP_1994("); pRenderFields.AddField("GDP_1999(", "GDP_1999("); pChartRenderer.CreateLegend();//生成图例 pGeoFeatLyr.Renderer = pChartRenderer as IFeatureRenderer; this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); this.axTOCControl.Update(); }
//PieChartRenderer private void button7_Click(object sender, EventArgs e) { IGeoFeatureLayer geoFeatureLayer; IFeatureLayer featureLayer; ITable table; ICursor cursor; IRowBuffer rowBuffer; //设置饼图的要素 string field1 = "sqmi"; string field2 = "sqkm"; //获取渲染图层 geoFeatureLayer = getGeoLayer("Continents"); featureLayer = geoFeatureLayer as IFeatureLayer; table = featureLayer as ITable; geoFeatureLayer.ScaleSymbols = true; IChartRenderer chartRenderer = new ChartRendererClass(); IPieChartRenderer pieChartRenderer = chartRenderer as IPieChartRenderer; IRendererFields rendererFields = chartRenderer as IRendererFields; rendererFields.AddField(field1, field1); rendererFields.AddField(field2, field2); int[] fieldIndexs = new int[2]; fieldIndexs[0] = table.FindField(field1); fieldIndexs[1] = table.FindField(field2); //获取渲染要素的最大值 double fieldValue = 0.0, maxValue = 0.0; cursor = table.Search(null, true); rowBuffer = cursor.NextRow(); while (rowBuffer != null) { for (int i = 0; i < 2; i++) { fieldValue = double.Parse(rowBuffer.get_Value(fieldIndexs[i]).ToString()); if (fieldValue > maxValue) { maxValue = fieldValue; } } rowBuffer = cursor.NextRow(); } //设置饼图符号 IPieChartSymbol pieChartSymbol = new PieChartSymbolClass(); pieChartSymbol.Clockwise = true; pieChartSymbol.UseOutline = true; IChartSymbol chartSymbol = pieChartSymbol as IChartSymbol; chartSymbol.MaxValue = maxValue; ILineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = getRGB(255, 0, 0); lineSymbol.Width = 2; pieChartSymbol.Outline = lineSymbol; IMarkerSymbol markerSymbol = pieChartSymbol as IMarkerSymbol; markerSymbol.Size = 30; //添加渲染符号 ISymbolArray symbolArray = pieChartSymbol as ISymbolArray; IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = getRGB(0, 255, 0); symbolArray.AddSymbol(fillSymbol as ISymbol); fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = getRGB(0, 0, 255); symbolArray.AddSymbol(fillSymbol as ISymbol); chartRenderer.ChartSymbol = pieChartSymbol as IChartSymbol; fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = getRGB(100, 100, 100); chartRenderer.BaseSymbol = fillSymbol as ISymbol; chartRenderer.UseOverposter = false; //创建图例 chartRenderer.CreateLegend(); geoFeatureLayer.Renderer = chartRenderer as IFeatureRenderer; this.axMapControl1.Refresh(); }
private void method_4() { if (this.igeoFeatureLayer_0 == null) { this.ichartRenderer_0 = null; } else { IChartRenderer pInObject = this.igeoFeatureLayer_0.Renderer as IChartRenderer; if (pInObject == null) { if (this.ichartRenderer_0 == null) { this.ichartRenderer_0 = new ChartRendererClass(); if (this.int_0 == 0) { this.ichartRenderer_0.ChartSymbol = new PieChartSymbolClass(); } else if (this.int_0 == 1) { this.ichartRenderer_0.ChartSymbol = new BarChartSymbolClass(); } else { this.ichartRenderer_0.ChartSymbol = new StackedChartSymbolClass(); } (this.ichartRenderer_0.ChartSymbol as IMarkerSymbol).Size = 32.0; } } else { IObjectCopy copy = new ObjectCopyClass(); this.ichartRenderer_0 = copy.Copy(pInObject) as IChartRenderer; IChartSymbol chartSymbol = this.ichartRenderer_0.ChartSymbol; IChartSymbol symbol2 = null; if (this.int_0 == 0) { if (!(chartSymbol is IPieChartSymbol)) { symbol2 = new PieChartSymbolClass(); } } else if (this.int_0 == 1) { if (!(chartSymbol is IBarChartSymbol)) { symbol2 = new BarChartSymbolClass(); } } else if ((this.int_0 == 2) && !(chartSymbol is IStackedChartSymbol)) { symbol2 = new StackedChartSymbolClass(); } if (symbol2 != null) { ISymbolArray array = chartSymbol as ISymbolArray; for (int i = 0; i < array.SymbolCount; i++) { (symbol2 as ISymbolArray).AddSymbol(array.get_Symbol(i)); } this.ichartRenderer_0.ChartSymbol = symbol2; } } } }
private void btn_OK_Click(object sender, EventArgs e) { string LayerName = cbx_Layer.SelectedItem.ToString(); IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)m_FeatureLayer; ITable pTable = (ITable)pGeoFeatureLayer; ICursor pCursor = pTable.Search(null, true); int numFields = lstbx_RightFields.Items.Count; string[] fildName = new string[numFields]; int[] fieldIndecies = new int[numFields]; for (int i = 0; i < numFields; i++) { if (lstbx_RightFields.Items[i].ToString() != "None") { fildName[i] = lstbx_RightFields.Items[i].ToString(); fieldIndecies[i] = pTable.FindField(fildName[i]); } else { MessageBox.Show("不可用的字段,请选择其它图层"); return; } } //fieldIndecies[0] = pTable.FindField(strPopField1); //fieldIndecies[1] = pTable.FindField(strPopField2); bool firstValue = true; double dmaxValue = 0.0; //Iterate across each feature IRowBuffer pRowBuffer = pCursor.NextRow(); double dfieldValue; while (pRowBuffer != null) { // iterate through each data field and update the maxVal if needed for (int lfieldIndex = 0; lfieldIndex <= numFields - 1; lfieldIndex++) { dfieldValue = (double)pRowBuffer.get_Value(fieldIndecies[lfieldIndex]); if (firstValue) { // Special case for the first value in a feature class dmaxValue = dfieldValue; firstValue = false; } else { if (dfieldValue > dmaxValue) { // we've got a new biggest value dmaxValue = dfieldValue; } } } pRowBuffer = pCursor.NextRow(); } if (dmaxValue <= 0) { MessageBox.Show("Failed to gather stats on the feature class"); return; } IChartRenderer pChartRenderer = new ChartRendererClass(); //Set up the fields to draw charts of IRendererFields pRendererFields = (IRendererFields)pChartRenderer; for (int i = 0; i < numFields; i++) { pRendererFields.AddField(fildName[i], fildName[i]); } // Set up the chart marker symbol to use with the renderer IPieChartSymbol pPieChartSymbol; pPieChartSymbol = new PieChartSymbolClass(); //饼图使用顺时针方法 pPieChartSymbol.Clockwise = true; //饼图有外轮廓线 pPieChartSymbol.UseOutline = true; IChartSymbol pChartSymbol = (IChartSymbol)pPieChartSymbol; pChartSymbol.MaxValue = dmaxValue; ILineSymbol pOutline; pOutline = new SimpleLineSymbolClass(); pOutline.Color = getRGB(213, 212, 252); pOutline.Width = 1; //设置外轮廓线的样式 pPieChartSymbol.Outline = pOutline; IMarkerSymbol pMarkerSymbol = (IMarkerSymbol)pPieChartSymbol; pMarkerSymbol.Size = 8; IColorRamp pColorRamp = (IColorRamp)m_StyleGallertItem.Item; pColorRamp.Size = pTable.RowCount(null); bool ok = true; pColorRamp.CreateRamp(out ok); IEnumColors pEnumRamp = pColorRamp.Colors; IFillSymbol pFillSymbol; ISymbolArray pSymbolArray = (ISymbolArray)pPieChartSymbol; for (int i = 0; i < numFields; i++) { pFillSymbol = new SimpleFillSymbolClass(); for (int j = 0; j < 8; j++) { pEnumRamp.Next(); } pFillSymbol.Color = pEnumRamp.Next(); pSymbolArray.AddSymbol((ISymbol)pFillSymbol); } //Now set the barchart symbol into the renderer pChartRenderer.ChartSymbol = (IChartSymbol)pPieChartSymbol; // pChartRenderer.Label = "Population"; //set up the background symbol to use tan color pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = m_BackGroundColor; pChartRenderer.BaseSymbol = (ISymbol)pFillSymbol; pChartRenderer.UseOverposter = false; IPieChartRenderer pPieChartRenderer = pChartRenderer as IPieChartRenderer; pPieChartRenderer.MinSize = 3; //设置最小值,用于尺寸比例 pPieChartRenderer.MinValue = 453588; pPieChartRenderer.FlanneryCompensation = false; pPieChartRenderer.ProportionalBySum = true; //pChartRenderer.Label = "Population"; //产生图例对象 pChartRenderer.CreateLegend(); //pdate the renderer and refresh the screen pGeoFeatureLayer.Renderer = (IFeatureRenderer)pChartRenderer; m_MapControl.ActiveView.ContentsChanged(); m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }