# Save a Bar Graph Image to File

**URL:** <https://forum.inductiveautomation.com/t/save-a-bar-graph-image-to-file/5347>\
**Category:** General Discussion\
**Created:** [October 29, 2012, 4:43pm UTC](https://forum.inductiveautomation.com/t/save-a-bar-graph-image-to-file/5347 "2012-10-29T16:43:56Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkrugerud](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@jkrugerud](https://forum.inductiveautomation.com/u/jkrugerud)\
**Post date:** [October 29, 2012, 4:43pm UTC](https://forum.inductiveautomation.com/t/save-a-bar-graph-image-to-file/5347/1 "2012-10-29T16:43:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [October 29, 2012, 5:06pm UTC](https://forum.inductiveautomation.com/t/save-a-bar-graph-image-to-file/5347/2 "2012-10-29T17:06:12Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![greg.simpson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/greg.simpson/32/3135_2.png) [@greg.simpson](https://forum.inductiveautomation.com/u/greg.simpson)\
**Post date:** [October 29, 2012, 5:07pm UTC](https://forum.inductiveautomation.com/t/save-a-bar-graph-image-to-file/5347/3 "2012-10-29T17:07:27Z")

</div>

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()`

---

<div class="post-metadata">

**Author:** ![jkrugerud](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@jkrugerud](https://forum.inductiveautomation.com/u/jkrugerud)\
**Post date:** [October 29, 2012, 5:19pm UTC](https://forum.inductiveautomation.com/t/save-a-bar-graph-image-to-file/5347/4 "2012-10-29T17:19:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 29, 2012, 5:22pm UTC](https://forum.inductiveautomation.com/t/save-a-bar-graph-image-to-file/5347/5 "2012-10-29T17:22:12Z")

</div>

Secret option B:

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

---

<div class="post-metadata">

**Author:** ![greg.simpson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/greg.simpson/32/3135_2.png) [@greg.simpson](https://forum.inductiveautomation.com/u/greg.simpson)\
**Post date:** [October 29, 2012, 5:23pm UTC](https://forum.inductiveautomation.com/t/save-a-bar-graph-image-to-file/5347/6 "2012-10-29T17:23:22Z")

</div>

[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:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")

---

<div class="post-metadata">

**Author:** ![jkrugerud](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@jkrugerud](https://forum.inductiveautomation.com/u/jkrugerud)\
**Post date:** [October 29, 2012, 7:18pm UTC](https://forum.inductiveautomation.com/t/save-a-bar-graph-image-to-file/5347/7 "2012-10-29T19:18:27Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 29, 2012, 7:39pm UTC](https://forum.inductiveautomation.com/t/save-a-bar-graph-image-to-file/5347/8 "2012-10-29T19:39:12Z")

</div>

The reason I say to put it in a container is that I’ve not really had good luck with just making the image:  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/534a22eb315e275db41c6371fac935988d418f57.jpg)  
  
Putting it in it’s own container gives it a good, stable background:  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/bf1cbacdfe6f17485ae42b36546254558ed58fe7.png)

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](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/fde65801131a75f10804d70b4e55054b1bbe855b.vwin) (9.12 KB)

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [October 29, 2012, 10:06pm UTC](https://forum.inductiveautomation.com/t/save-a-bar-graph-image-to-file/5347/9 "2012-10-29T22:06:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jkrugerud](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@jkrugerud](https://forum.inductiveautomation.com/u/jkrugerud)\
**Post date:** [October 29, 2012, 10:08pm UTC](https://forum.inductiveautomation.com/t/save-a-bar-graph-image-to-file/5347/10 "2012-10-29T22:08:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [October 29, 2012, 10:22pm UTC](https://forum.inductiveautomation.com/t/save-a-bar-graph-image-to-file/5347/11 "2012-10-29T22:22:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jkrugerud](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@jkrugerud](https://forum.inductiveautomation.com/u/jkrugerud)\
**Post date:** [October 29, 2012, 10:34pm UTC](https://forum.inductiveautomation.com/t/save-a-bar-graph-image-to-file/5347/12 "2012-10-29T22:34:21Z")

</div>

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.
