AnsweredAssumed Answered

python and pie charts

Question asked by cynthiak on May 18, 2017
Latest reply on May 23, 2017 by cynthiak

I can not figure this out.  I have a python script that runs as a script in a Toolbox.  The script takes features that are selected, performs some calculations and creates two tables.  One table is used to generate a report and the other table is used to generate a pie chart.  The report has a graphic element at the top that is supposed to reference the jpeg of the pie chart.  However when the script tool runs, the pie chart is not created, and thus, a blank space shows up on the report.  I took the portion of the script that creates the pie chart and then the report (that portion below) and saved it to another script and ran this directly in the ArcMap python window and it works perfect, so I know that the elements of the scripting are working.  I really need this to work through the Toolbox, though.  Any suggestions?

 

This is the script that creates the report.

 

#Recreate the graph for the report......
#Set local variables....
output_graph_name = "NitrogenAvailability"
output_graph_jpg = "\\\\GIS-Cascade\\Data\\Geodatabase\\earth\\GWMA\\Summary\\Reports\\GWMA_PieChart.jpg"
graph_grf = "\\\\GIS-Cascade\\Data\\Geodatabase\\earth\\GWMA\\Summary\\Reports\\NitrogenAvailability.grf"
inputData = "\\\\GIS-Cascade\\Data\\Geodatabase\\earth\\GWMA\\Summary\Reports\\selections.gdb\\pieTable"

if os.path.exists(output_graph_jpg):
   os.remove(output_graph_jpg)

#Create the graph.......
graph = arcpy.Graph()

#Add a pie chart.......
graph.addSeriesPie(inputData, "Nitrogen", "", "NSource")

#Output a graph, which is created in-memory
arcpy.MakeGraph_management(graph_grf, graph, output_graph_name)

#Save the graph as an image....
arcpy.SaveGraph_management(output_graph_name, output_graph_jpg, "IGNORE_ASPECT_RATIO", "500", "300")

#Create a Report of the Nitrogen Table to Summarize the Final Numbers.....
newreport = "nitrogen"
newreportpath = "\\\\GIS-Cascade\\Data\\Geodatabase\\earth\\GWMA\\Summary\\Reports\\" + newreport + ".pdf"
mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd)[0]
table = "\\\\GIS-Cascade\\Data\\Geodatabase\\earth\\GWMA\\Summary\\Reports\\selections.gdb\\nitrogen"
tabView = arcpy.mapping.TableView("\\\\GIS-Cascade\\Data\\Geodatabase\\earth\\GWMA\\Summary\\Reports\\selections.gdb\\nitrogen")
arcpy.mapping.AddTableView(df, tabView)
table = arcpy.mapping.ListTableViews(mxd, "nitrogen", df)[0]
arcpy.mapping.ExportReport(table, "\\\\GIS-Cascade\\Data\\Geodatabase\\earth\\GWMA\\Summary\\Reports\\total_nitrogen_summary.rlf", newreportpath)

Outcomes