ChartType = (ctBarChart, ctPieChart, ctStackedChart);
//创建柱状 饼状 stacked 专题
//参数依次为 图层,字段集合,专题样式,chart大小,是否垂直放置(默认为否)
var
pGeoLayer: IGeoFeatureLayer;
pRenderer: IChartRenderer;
pMarkerSymbol: IMarkerSymbol;
pRendererFields: IRendererFields;
vMaxVaule, value: Variant;
pCursor : ICursor;
pDataStatics: IDataStatistics;
pChartSymbol: IChartSymbol;
pSymbolArray: ISymbolArray;
pFillSymbol: ISimpleFillSymbol;
pNormaliztion: IDataNormalization;
pColor : IColor;
pBarChartSymbol: IBarChartSymbol;
pPieChartRenderer: IPieChartRenderer;
pPieChartSymbol: IPieChartSymbol;
pStackedChartSymbol: IStackedChartSymbol;
I : Integer;
begin
pGeoLayer := pLayer as IGeoFeatureLayer;
pRenderer := CoChartRenderer.Create as IChartRenderer;
case eChartSyle of
ctBarChart:
begin
pBarChartSymbol := CoBarChartSymbol.Create as IBarChartSymbol;
pBarChartSymbol.VerticalBars := IsVerticalBar;
pBarChartSymbol.Width := 5;
pChartSymbol := pBarChartSymbol as IChartSymbol;
end;
ctPieChart:
begin
pPieChartSymbol := CoPieChartSymbol.Create as IPieChartSymbol;
pPieChartSymbol.Clockwise := True;
pPieChartSymbol.UseOutline := True;
//使用 IPieChartRenderer 接口,来设置Piechart的高级属性
pPieChartRenderer := pRenderer as IPieChartRenderer;
pPieChartRenderer.ProportionalBySum := True; //饼图的直径和值相关
pPieChartRenderer.MinSize := 2; //最小符号大小
pPieChartRenderer.MinValue := 0.07; //用于渲染的最小值
pChartSymbol := pPieChartSymbol as IChartSymbol;
end;
ctStackedChart:
begin
pStackedChartSymbol := CoStackedChartSymbol.Create as IStackedChartSymbol;
pStackedChartSymbol.Width := 5;
pStackedChartSymbol.VerticalBar := IsVerticalBar;
pChartSymbol := pStackedChartSymbol as IChartSymbol;
end;
end;
pSymbolArray := pChartSymbol as ISymbolArray;
pRendererFields := pRenderer as IRendererFields;
vMaxVaule := 0;
//循环,统计所有值中的最大值并为每个要渲染的属性创建填充符号
pDataStatics := CoDataStatistics.Create as IDataStatistics;
for I := 0 to sField.Count - 1 do
begin
pRendererFields.AddField(sField.ValueFromIndex[I], sField.Names[I]);
pDataStatics.Cursor := pGeoLayer.Search(nil, True) as ICursor;
pDataStatics.Field := sField.ValueFromIndex[I];
value := pDataStatics.Statistics.Maximum;
if value > vMaxVaule then
begin
vMaxVaule := value;
end;
//创建统计图表各个部分的填充颜色
pFillSymbol := CoSimpleFillSymbol.Create as ISimpleFillSymbol;
pFillSymbol.Color := GetRandomColor();
pSymbolArray.AddSymbol(pFillSymbol as ISymbol);
end;
pChartSymbol.MaxValue := vMaxVaule;
pMarkerSymbol := pChartSymbol as IMarkerSymbol;
pMarkerSymbol.Size := iChartSize;
//填充背景
pFillSymbol := CoSimpleFillSymbol.Create as ISimpleFillSymbol;
pFillSymbol.Color := getRGB(157, 225, 215, 255);
pRenderer.ChartSymbol := pChartSymbol;
pRenderer.Label_ := '刘军生';
pRenderer.UseOverposter := True; //当位置不够时可以移位
pRenderer.CreateLegend;
if pRenderer <> nil then
begin
pRenderer.BaseSymbol := pFillSymbol as ISymbol;
pGeoLayer.Renderer := pRenderer as IFeatureRenderer;
Result := True;
end
else
Result := False;
end;