# Charts - Directly Display Live Data From SQL Tags

**URL:** <https://forum.inductiveautomation.com/t/charts-directly-display-live-data-from-sql-tags/2189>\
**Category:** Ignition\
**Created:** [September 13, 2010, 6:40pm UTC](https://forum.inductiveautomation.com/t/charts-directly-display-live-data-from-sql-tags/2189 "2010-09-13T18:40:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhoag](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rhoag](https://forum.inductiveautomation.com/u/rhoag)\
**Post date:** [September 13, 2010, 6:40pm UTC](https://forum.inductiveautomation.com/t/charts-directly-display-live-data-from-sql-tags/2189/1 "2010-09-13T18:40:05Z")

</div>

Does anyone know how to directly display the value of a SQL Tag in a chart (bar, graph, or pie) without querying the database?

I have a client that would like to convert an Allen Bradley Panelview Plus project over to a Vision Panel but the one hang up is that the Panelview Plus has a few live trends that operators use for setting up the machine and I don’t see away to do this without have external database.

---

<div class="post-metadata">

**Author:** ![lancekornoelje](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@lancekornoelje](https://forum.inductiveautomation.com/u/lancekornoelje)\
**Post date:** [September 13, 2010, 7:01pm UTC](https://forum.inductiveautomation.com/t/charts-directly-display-live-data-from-sql-tags/2189/2 "2010-09-13T19:01:11Z")

</div>

I have used a timer with some scripting to create a dataset that can be charted. However, the data is only temporary - it lives in real-time on the window, so any project updates, window closures, etc. delete the data… Another option is to talk with your sales rep to see if you can get a tag-limited / client-limited Vision module so that you still have DB access without multiple clients.

---

<div class="post-metadata">

**Author:** ![rhoag](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rhoag](https://forum.inductiveautomation.com/u/rhoag)\
**Post date:** [September 13, 2010, 7:12pm UTC](https://forum.inductiveautomation.com/t/charts-directly-display-live-data-from-sql-tags/2189/3 "2010-09-13T19:12:16Z")

</div>

Lance,

That’s what I’m looking to do. Can you post a sample of your script?

Inductive Automation Delevopers,

It would be nice to be able to just add the SQL tags to a chart without having to create a script.

Thanks

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [September 13, 2010, 7:23pm UTC](https://forum.inductiveautomation.com/t/charts-directly-display-live-data-from-sql-tags/2189/4 "2010-09-13T19:23:07Z")

</div>

If you are doing a live trend and you want to keep adding to a dataset, you could add a date dynamic property to the Root Container bound to:`now(5000)`That will make the property refresh every 5 seconds. You can then add a Property Change script on the Root Container with the following code:`from java.util import Date
if event.propertyName == "date":
	chart = event.source.getComponent('Chart')
	val1 = system.tag.getTagValue("RAMP/RAMP1")
	val2 = system.tag.getTagValue("RAMP/RAMP2")
	chart.Data = system.dataset.addRow(chart.Data, [Date(), val1, val2])` If you want to make it a rolling chart do this:[code]from java.util import Date  
if event.propertyName == “date”:  
chart = event.source.getComponent(‘Chart’)  
val1 = system.tag.getTagValue(“RAMP/RAMP1”)  
val2 = system.tag.getTagValue(“RAMP/RAMP2”)

```
if chart.Data.getRowCount() > 60:
	chart.Data = system.dataset.deleteRow(chart.Data, 0)

chart.Data = system.dataset.addRow(chart.Data, [Date(), val1, val2])[/code] Here you delete records older then 5 minutes ago.

```

Note \*: The above example assumes your dataset already has these three columns t\_stamp as datetime, val1 as float and val2 as float. You can go into the dataset editor to add/edit/remove these columns.

If the number of rows in your dataset is static you can just use the cellUpdate binding to dynamically change a cell’s value. Hope this helps.

---

<div class="post-metadata">

**Author:** ![lancekornoelje](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@lancekornoelje](https://forum.inductiveautomation.com/u/lancekornoelje)\
**Post date:** [September 13, 2010, 7:35pm UTC](https://forum.inductiveautomation.com/t/charts-directly-display-live-data-from-sql-tags/2189/5 "2010-09-13T19:35:50Z")

</div>

I’m sure the others can do it much more eloquently, but here is the actionPerformed script I put into a timer object, and using a chart component. I used the values from the OPC simulator.

#get current time  
from java.util import Date  
currentDateTime = Date()

#read SQL tag values you want  
tagValue1 = system.tag.getTagValue(’[]Overview/Motor 1/Amps’)  
tagValue2 = system.tag.getTagValue(’[]Overview/Motor 2/Amps’)

#assemble data into an array  
newRow = [currentDateTime,tagValue1,tagValue2]

#read old dataset and append the new row  
ds1 = event.source.parent.getComponent(‘Chart’).Data  
ds1 = system.dataset.addRow(ds1,newRow)

#pass updated dataset back to the chart  
event.source.parent.getComponent(‘Chart’).Data = ds1
