这几天一直看AE,几天看下来没什么头绪,日子过得恍恍忽忽.今天终于写了一个程序练练手,根据帮助的VB程序改编的,在众多的接口之间跳来跳去,晕头转向.现把代码贴出来,给处在迷茫中的朋友一点小启示,也以此自勉!
画饼图,C#实现:
private RgbColor GetRgbColor(int red,int green,int blue)
{
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,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();
}
来自:http://www.3snews.net/html/47/6447-9536.html
原文链接:https://www.f2er.com/vb/259454.html