<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Add chart to layer in map from Script Tool output in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/add-chart-to-layer-in-map-from-script-tool-output/m-p/1232121#M62290</link>
    <description>&lt;P&gt;Sorry for the disappointment but a restart of Pro has fixed my problem.&lt;/P&gt;&lt;P&gt;Hope the code might help someone and please reach out if you have questions.&lt;/P&gt;&lt;P&gt;Nick&lt;/P&gt;</description>
    <pubDate>Wed, 16 Nov 2022 08:36:14 GMT</pubDate>
    <dc:creator>NickMiddleton</dc:creator>
    <dc:date>2022-11-16T08:36:14Z</dc:date>
    <item>
      <title>Add chart to layer in map from Script Tool output</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/add-chart-to-layer-in-map-from-script-tool-output/m-p/1232109#M62289</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can an Arcpy Script Tool add a chart to a layer in a map?&lt;/P&gt;&lt;P&gt;The offending script will add the desired chart when the code is run from the Python Window as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;lyrTemporalSamples = arcpy.GetParameterAsText(0)
inStationName =  arcpy.GetParameterAsText(1)
inBoreName = arcpy.GetParameterAsText(2)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help appreciated,&lt;/P&gt;&lt;P&gt;Nick&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 07:21:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/add-chart-to-layer-in-map-from-script-tool-output/m-p/1232109#M62289</guid>
      <dc:creator>NickMiddleton</dc:creator>
      <dc:date>2022-11-16T07:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: Add chart to layer in map from Script Tool output</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/add-chart-to-layer-in-map-from-script-tool-output/m-p/1232121#M62290</link>
      <description>&lt;P&gt;Sorry for the disappointment but a restart of Pro has fixed my problem.&lt;/P&gt;&lt;P&gt;Hope the code might help someone and please reach out if you have questions.&lt;/P&gt;&lt;P&gt;Nick&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 08:36:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/add-chart-to-layer-in-map-from-script-tool-output/m-p/1232121#M62290</guid>
      <dc:creator>NickMiddleton</dc:creator>
      <dc:date>2022-11-16T08:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Add chart to layer in map from Script Tool output</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/add-chart-to-layer-in-map-from-script-tool-output/m-p/1232123#M62291</link>
      <description>&lt;P&gt;I have no experience in the creation of "script tool", but in scripts with python and arcpy I do.&lt;/P&gt;&lt;P&gt;I would recommend try to make a old school debug technique:&lt;/P&gt;&lt;P&gt;In the line 8 set&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;print(lyrTemporalSamples)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;at least in that way you will know if the value is passed through the parameters. also validate the&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;aprx &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;variable, to know if the current map is taken.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 08:38:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/add-chart-to-layer-in-map-from-script-tool-output/m-p/1232123#M62291</guid>
      <dc:creator>Cristian_Galindo</dc:creator>
      <dc:date>2022-11-16T08:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Add chart to layer in map from Script Tool output</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/add-chart-to-layer-in-map-from-script-tool-output/m-p/1233470#M62445</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/7838"&gt;@NickMiddleton&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thanks for the question! The preferred way of adding charts to an output layer or table in a tool is to set the&amp;nbsp; `charts` property of the output parameter (see the following &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/parameter.htm" target="_self"&gt;documentation&lt;/A&gt; for more information).&lt;/P&gt;&lt;P&gt;To illustrate, I've created a simple script tool with the following parameters:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="callen_esri_3-1668816340799.png" style="width: 935px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/56404iE6FCACA4B3F0319D/image-dimensions/935x125?v=v2" width="935" height="125" role="button" title="callen_esri_3-1668816340799.png" alt="callen_esri_3-1668816340799.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And the following tool code creates a new chart and adds it to the derived output layer by setting the `charts` property:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

# capture the derived output layer parameter
output = arcpy.GetParameterInfo()[1]

# create the chart 
chart = arcpy.charts.Bar(x='neighbourhood_group', aggregation='count')

# add chart to the output layer by setting the `charts` property on the parameter
output.charts = [chart]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps, but please feel free to reach out if you have any additional questions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Take care,&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2022 00:14:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/add-chart-to-layer-in-map-from-script-tool-output/m-p/1233470#M62445</guid>
      <dc:creator>ChristopherAllen</dc:creator>
      <dc:date>2022-11-19T00:14:55Z</dc:date>
    </item>
  </channel>
</rss>

