# SQL data and Perspective Chart’s with query binding

**URL:** <https://forum.inductiveautomation.com/t/sql-data-and-perspective-chart-s-with-query-binding/103802>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [March 17, 2025, 6:42pm UTC](https://forum.inductiveautomation.com/t/sql-data-and-perspective-chart-s-with-query-binding/103802 "2025-03-17T18:42:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shubham\_Dhoke](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/shubham_dhoke/32/85510_2.png) [@shubham\_Dhoke](https://forum.inductiveautomation.com/u/shubham_Dhoke)\
**Post date:** [March 17, 2025, 6:42pm UTC](https://forum.inductiveautomation.com/t/sql-data-and-perspective-chart-s-with-query-binding/103802/1 "2025-03-17T18:42:24Z")

</div>

Hello there, everyone.

This is Shubham. i am from india  
I am learning something new, and I need your help.

i am working on a project, in which i am collecting input from the user (using data entry form) that data is stored in database (SSMS) (it has 20 columns)

So, i have created a view and added a prospective chart on it (its a view, not report)  
lets say i have added a 'bar' or 'pie' chart and in this bar chart i wanted to show count of distinct value from status column (i have column named Status in my SSMS table)

How can I do that? please suggest solution or approach  
(charts is to be real-time; if data is inserted/updated in table, charts must be populated immediately.)

Please let me know how I should approach this development.

Regards,  
Shubham

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [March 17, 2025, 6:52pm UTC](https://forum.inductiveautomation.com/t/sql-data-and-perspective-chart-s-with-query-binding/103802/2 "2025-03-17T18:52:03Z")

</div>

This is pretty easy to do. Here are somethings you'll need:

1. A Named Query that returns the Status and number of occurrences of that status, something like

```plaintext
StatusName | Count
Running | 12
Down | 5
Off | 6

```

1. A view with a chart on it, either a Bar or Pie chart (or any chart)
2. A Query binding on the charts `data` property that references your NQ above.
3. On your form `Submit` button, a `refreshBinding(self.data)` call to refresh the chart's `data` binding every time you insert table data OR if the data form is in a popup, a message handler that will do the same thing.

So, the data flow would be like this:

User clicks `Submit` -\> data inserted to DB -\> `refreshBinding()` called on Chart's `data` property that has the NQ binding

Default Pie chart:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/4/e4dc974dc2aab3aa1a4b9d58011b58feb797c710.png)

You can copy the `data[i]` formatting pretty much exactly, except instead of `flavor` and `count`, you can have something like `status` and `count`.
