HOW TO
There is no dynamic link between a chart and a view. Use this script when you need to display a chart with the same colors used in a view's legend.
Code:
theView = av.GetActiveDoc
theTheme = theView.GetActiveThemes.Get(0)
theLegend = theTheme.GetLegend
theType = theLegend.GetLegendType
If (theType <> #LEGEND_TYPE_UNIQUE) then
MsgBox.Info("This script will only work when using the"+nl+
"'Unique Value' legend type.","Wrong Legend Type")
return nil
End
theDocs = av.GetProject.GetDocs
theChartList = {}
for each d in theDocs
If (d.GetClass.GetClassName = "Chart") then
theChartList.Add(d)
end
end
theChart = MsgBox.ListAsString(theChartList,
"Select the appropriate Chart","Chart Select")
if(theChart = Nil) then
return nil
elseIf (theChart.IsSeriesFromRecords.Not) then
return nil
end
theChartDisplay = theChart.GetChartDisplay
for each i in 0..(theChartDisplay.GetNumSeries - 1)
seriesname = theChart.GetSeriesLabel(i)
'msgbox.info(seriesname,"SeriesName")
for each x in 0..(theLegend.GetNumClasses - 1)
classname = theLegend.ReturnClassInfo(x).Get(0) ' label name
'msgbox.info(classname,"ClassName")
if(seriesname = classname) then
aSymbol = theLegend.ReturnClassInfo(x).get(2) ' symbol
aColor = aSymbol.GetColor
theChartDisplay.SetSeriesColor(i,aColor)
break
end
end
end
If (seriesname <> classname) then
MsgBox.Info("The specified Chart does not have a field selected in the"+nl+
"'Label serieds using:' box in the Chart Properties Dialog."+nl+
"Please select the same field used to classify the Legend"+nl+
"in the View.","")
end
Note:
This script will only change the color of the chart symbols. Only a solid fill pattern can be used to symbolize a chart.
Article ID:000004958
Get help from ArcGIS experts
Download the Esri Support App