Hi All,
Can an Arcpy Script Tool add a chart to a layer in a map?
The offending script will add the desired chart when the code is run from the Python Window as below:
import arcpy
import os
import datetime
lyrTemporalSamples = "samples1452temporal" #arcpy.GetParameterAsText(0)
inStationName = "Vanesk Station" #arcpy.GetParameterAsText(1)
inBoreName = "All Bores" #arcpy.GetParameterAsText(2)
aprx = arcpy.mp.ArcGISProject("CURRENT")
map = aprx.listMaps("Halo")[0]
lyr = map.listLayers(lyrTemporalSamples)[0]
arcpy.env.addOutputsToMap = True
c = arcpy.Chart('TVCByDistance')
c.type = 'line'
c.dataSource = lyr
c.title = f"{inStationName}: Total Vegetative Cover By Distance from {inBoreName}"
c.yAxis.field = 'TVC'
c.yAxis.title = "% Total Vegetative Cover"
c.xAxis.field = 'distance'
c.xAxis.title = "Distance from a bore in metres (-9999 = no bore)"
c.line.aggregation = "MEAN"
c.line.splitCategory = "date_str"
c.addToLayer(lyr)
c.updateChart()
But when run it from a script tool with lines 5-7 above modified to the following the tool runs but doesn't add the chart:
lyrTemporalSamples = arcpy.GetParameterAsText(0)
inStationName = arcpy.GetParameterAsText(1)
inBoreName = arcpy.GetParameterAsText(2)
Any help appreciated,
Nick