Hi
Got an odd one with the charts module and MakeFeatureLayer. Code will work fine if you run it inside the ArcPro py window but if it's outside ArcPro as standalone script or run from inside a GP toolbox script, the result is a catastrophic app crash with the 'please report crash dialog' showing up 😞
basic code:
import arcpy
import os
source_fc = "chart-issues.gdb\\pts"
profile_name = "AB"
query_def = "Name='{}'".format(profile_name)
print(query_def)
r_chart_layer = arcpy.management.MakeFeatureLayer(source_fc, "chart_layer", query_def, None, None)
profile_chart = arcpy.charts.Line(
x="M",
y=["Z"],
dataSource = r_chart_layer.getOutput(0),
title="Elevation Over Distance: {}".format(profile_name),
xTitle = "Distance (Feet)",
yTitle = "Elevation (Feet)"
)
print("chart initialized")
chart_path = arcpy.CreateUniqueName(os.path.join("{}.svg".format(profile_name)), arcpy.env.scratchFolder)
print(chart_path)
profile_chart.exportToSVG(chart_path, 500, 500)
print("qed")
I tried a ton of variations and found a few extra nuggets.
There are work arounds but seems like you should be able to MakeFeatureLayer() and assign it as a chart data source without any extra steps.
Outside of Pro, the script knows nothing about the Project
Valid data sources include paths to datasets, including local datasets, UNC paths, and service URLs, and arcpy.mp Layer objects.
From the help topic on line charts, you might want to try saving your layer as a *.lyrx and use the full path to it as the datasource