1

I have three graphs in my layout created from feature classes which have Page Definitions set to reference a data driven page. The table of each feature class shows the correct number of features as I scroll through the data driven pages. However, the corresponding graph of the table shows ALL the records, not the subset in the current ddp. Ideas?

2

Graph is a static thing, it won't auto-redraw.

The best approach that works for me is to have graphics as attachments to DDPs. Yes, they have to be created first.

This script below works with XY graph, which template saved in "vert_line.tee". After moving to next page I manually select points in the layer called 'pnts' in Table of Content. It has fields Chainage for (X) and DEM for Y. If you layer has page definition, you can select all of visible. Script redraw graph (element name in layout called SECTION), using selected records and graph template and saves modified graph to raster called Page_Name.emf in the folder of your choice

folder=arcpy.GetParameterAsText(0))

Finally script removes existing attachment (if any) and adds new one as attachment to current page.

It is a life saver with map series similar to this:

enter image description here

Have a look and see if you can modify it to suit your needs.

import arcpy, traceback, os, sys
from arcpy import env
extract=r'in_memory\extract'
table=r'in_memory\attach'
env.overwriteoutput=True
folder=arcpy.GetParameterAsText(0)
template=r'C:\URS-Data\URS-Data\ESRI\Tools\Graph_Maker\vert_line.tee'
try:
    def showPyMessage():
        arcpy.AddMessage(str(time.ctime()) + " - " + message)
    def isLayerExist (mxd,lName):
        layers = arcpy.mapping.ListLayers(mxd,lName)
        if len(layers)==0:
            raise NameError,'\n'+lName + " layer not found. Exiting.."+'\n'
        result=layers[0]
        return result
    ## FIND ENVIRONMRNT TABLE
    mxd = arcpy.mapping.MapDocument("CURRENT")
    thePagesLayer = isLayerExist(mxd,"Pages")
    pageID = mxd.dataDrivenPages.currentPageID
    fld = mxd.dataDrivenPages.pageNameField.name
    Page_Names=arcpy.da.TableToNumPyArray(thePagesLayer, fld)
    fOut=folder+os.sep+Page_Names[pageID-1][0]+".emf"

    linkValue=Page_Names[pageID-1][0]
    attachName=Page_Names[pageID-1][0]+".emf"
    arcpy.CreateTable_management('in_memory', 'attach')
        arcpy.AddField_management(table, "Page", "TEXT", "", "", 25)
        arcpy.AddField_management(table, "Page2", "TEXT", "", "", 250)
        curT = arcpy.da.InsertCursor(table,("Page","Page2"))
        theRow=(linkValue,fOut)
        curT.insertRow(theRow)
    arcpy.RemoveAttachments_management(thePagesLayer,
                                           fld, table,
                                           "Page")
    thePointsLayer = isLayerExist(mxd,"pnts")
    source=thePointsLayer.dataSource
        bL=[row[0] for row in arcpy.da.TableToNumPyArray(source,"dem")]
        zMin,zMax=min(bL),max(bL)
        arcpy.CopyFeatures_management(thePointsLayer, extract)
        bigList=arcpy.da.TableToNumPyArray(extract,"CHAINAGE")
        n=len(bigList)
        lMax=bigList[n-1][0]
        p=arcpy.Point(0,0)
        curT = arcpy.da.InsertCursor(extract,("SHAPE@","dem", "CHAINAGE"))
        curT.insertRow((p,zMin,lMax))
        curT.insertRow((p,zMax,lMax))
        graph = arcpy.Graph()
        graph.addSeriesLineVertical (extract, "dem", "CHAINAGE")
        arcpy.MakeGraph_management(template, graph, "VerticalBarGraph")
##        # Save the graph as an image
        arcpy.SaveGraph_management("VerticalBarGraph",fOut,
                                   "IGNORE_ASPECT_RATIO", "1500", "450")
        arcpy.SelectLayerByAttribute_management (thePointsLayer, "CLEAR_SELECTION")
        arcpy.RefreshActiveView()
        arcpy.AddAttachments_management(thePagesLayer, fld,
                                        table, "Page", "Page2")
    del mxd
except:
    message = "\n*** PYTHON ERRORS *** "; showPyMessage()
    message = "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]; showPyMessage()
    message = "Python Error Info: " +  str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"; showPyMessage()

Any questions, ask

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.