{
RgbColor rgbColor = new RgbColorClass();
rgbColor.Red = red;
rgbColor.Green = green;
rgbColor.Blue = blue;
return rgbColor;
}
private void btnPieChart_Click(object sender, EventArgs e)
{
IMap pMap = new MapClass();
IFeatureLayer pFLayer = (IFeatureLayer)axMapControl1.get_Layer(0);
IGeoFeatureLayer pGeoFeaLayer = (IGeoFeatureLayer)pFLayer;
IChartRenderer pChartRenderer = new ChartRendererClass();
// Set up the field to draw charts
IRendererFields pRenderFields = (IRendererFields)pChartRenderer;
pRenderFields.AddField("Pop_cntry", null);
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("Pop_cntry");
ICursor pCursor = pTable.Search(pQueryFilter, true);
int fieldIndex;
double MaxValue;
bool firstValue;
double fieldValue;
fieldIndex = pTable.FindField("Pop_cntry");
firstValue = true;
MaxValue = 0;
IRowBuffer pRow = pCursor.NextRow();
while (pRow != null)
{
fieldValue =(double) pRow.get_Value(fieldIndex);
if (firstValue)
{
MaxValue = fieldValue;
firstValue = false;
}
if (fieldValue > MaxValue)
{
MaxValue = fieldValue;
}
pRow = pCursor.NextRow();
}
IPieChartSymbol pPiechartSymbol = new Pie ChartSymbolClass();
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 = MaxValue;
pMarkerSymbol.Size = 16;
ISymbolArray pSymbolArray = (ISymbolArray)pPiechartSymbol;
pFillSymbol.Color = GetRgbColor(213,212,252);
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 = 6;
pPieChartRender.MinValue = 453588;
pPieChartRender.FlanneryCompensation = false;
pPieChartRender.ProportionalBySum = true;
pChartRenderer.ChartSymbol = (IChartSymbol)pPiechartSymbol;
pChartRenderer.CreateLegend();
pGeoFeaLayer.Renderer =(IFeatureRenderer) pChartRenderer;
this.axLicenseControl1.Refresh();
}