Save a Bar Graph Image to File

Using a button and the printToImage script, how do I grab a bar chart as a component to print, if I just select the Chart component I get an error stating that I need to choose a property in the tree?

So this doesn’t work for you? What version of Ignition are you using?

system.print.printToImage(event.source.parent.getComponent("Bar Chart"),"Screen.jpg")

If the bar chart is the only item on the screen you could use the system.print.createPrintJob. This will print everything in that window.

job = system.print.createPrintJob(event.source.parent) job.setMargins(0.5) job.zoomFactor = 0.75 job.showPageFormat = 0 job.print()

I’m running 7.5.1, I would print the whole screen but its not the only chart on the screen and I dont care about the others.

Secret option B:

put the one you want to print in its own container, then print the container-- using the same script above.

[quote]Secret option B:

put the one you want to print in its own container, then print the container-- using the same script above.[/quote]

You read my mind :scratch:

I am able to do it that way but getting it to print to a file is more complicated than just using the printToImage, the operators who are going to be printing the bchart aren’t very computer illiterate so I would really like to use the printToImage (its there to be used). Below is the code I have behind a button which I placed in a container along with the bchart which still doesn’t work:

equip = event.source.parent.parent.getComponent(‘drpdwn_Equipment Select’).selectedStringValue
barChart = event.source.parent

system.print.printToImage(barChart,“Valve_Test_” + equip)

The reason I say to put it in a container is that I’ve not really had good luck with just making the image:

Putting it in it’s own container gives it a good, stable background:

You can make an image of the container just as easily as printing it.

Look at the attached window. Done in 7.2.11, so should still give you a good idea.
SaveGraphImage.vwin (9.12 KB)

That code you posted won’t work, the barChart variable is assigned incorrectly. You have to call getComponent() to get the bar chart:

[code]equip = event.source.parent.parent.getComponent(‘drpdwn_Equipment Select’).selectedStringValue
barChart = event.source.parent.getComponent(‘Bar Chart’)

system.print.printToImage(barChart,“Valve_Test_” + equip)[/code]

Also make sure that for the second parameter of printToImage(), you put .jpg or .png or something similar at the end of that filename string.

I did put the bchart into a container, I found the issue to be adding a file name. Once I removed the file path portion it worked fine. Can you test this on your end and let me know if adding a file path works for you?

The filename has to have a proper file extension (jpg, png, etc), does your filename string have that?

Oh ok, that fixed it, I didn’t think I needed that because I can use the export to Excel script without the file extension and it works fine. I’ll remember this in the future.