# Unable to apply SQL query binding to Chart, Bar Chart and Easy Chart

**URL:** <https://forum.inductiveautomation.com/t/unable-to-apply-sql-query-binding-to-chart-bar-chart-and-easy-chart/15422>\
**Category:** Ignition\
**Created:** [September 21, 2017, 5:18am UTC](https://forum.inductiveautomation.com/t/unable-to-apply-sql-query-binding-to-chart-bar-chart-and-easy-chart/15422 "2017-09-21T05:18:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![AkikRanade](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@AkikRanade](https://forum.inductiveautomation.com/u/AkikRanade)\
**Post date:** [September 21, 2017, 5:18am UTC](https://forum.inductiveautomation.com/t/unable-to-apply-sql-query-binding-to-chart-bar-chart-and-easy-chart/15422/1 "2017-09-21T05:18:08Z")

</div>

I am trying to apply a SQL query onto a Easy Chart to display energy consumption. The query worked perfectly with table but failed to work in Chart, Easy Chart & Bar Chart. In Chart it shows me configuration error. In Easy Chart it shows “column ‘Name’ is absent” error. In Bar Chart it doesn’t show ant error but Bar Chart comes blank.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 21, 2017, 12:44pm UTC](https://forum.inductiveautomation.com/t/unable-to-apply-sql-query-binding-to-chart-bar-chart-and-easy-chart/15422/2 "2017-09-21T12:44:06Z")

</div>

You can’t put your own SQL into an EasyChart. The Classic Chart (for time series) needs each dataset to have either a datetime, timestamp, or long integer (milliseconds) column as the first column, with all other columns interpreted as pen data.

---

<div class="post-metadata">

**Author:** ![AkikRanade](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@AkikRanade](https://forum.inductiveautomation.com/u/AkikRanade)\
**Post date:** [September 21, 2017, 3:42pm UTC](https://forum.inductiveautomation.com/t/unable-to-apply-sql-query-binding-to-chart-bar-chart-and-easy-chart/15422/3 "2017-09-21T15:42:38Z")

</div>

Ok, so not the Easy Chart. That’s a bummer 🙁 because I am better at writing SQL query than Python script to calculate my Consumption values. I was expecting it would work effortlessly since the component has all the features in-built that I require for my data representation.

Well, how about the Bar Chart & plain Chart. Both yielded blank charts on executing the SQL query. Calculating Consumption via Tag History is something that I’m not aware of.

Any help on that front would be highly appreciated. 🙂

---

<div class="post-metadata">

**Author:** ![carolina\_elfeky](https://avatars.discourse-cdn.com/v4/letter/c/8baadc/32.png) [@carolina\_elfeky](https://forum.inductiveautomation.com/u/carolina_elfeky)\
**Post date:** [September 21, 2017, 8:24pm UTC](https://forum.inductiveautomation.com/t/unable-to-apply-sql-query-binding-to-chart-bar-chart-and-easy-chart/15422/4 "2017-09-21T20:24:39Z")

</div>

Try changing the chart to a category chart and creating an x-axis that is a category. Also be sure to change the renderer to category line/shape renderer. These are properties in the chart customiizer.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 21, 2017, 8:46pm UTC](https://forum.inductiveautomation.com/t/unable-to-apply-sql-query-binding-to-chart-bar-chart-and-easy-chart/15422/5 "2017-09-21T20:46:08Z")

</div>

Please show the dataset that results from your query. Or a handful of rows from it. An excerpt from “copy to clipboard” would do.

---

<div class="post-metadata">

**Author:** ![AkikRanade](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@AkikRanade](https://forum.inductiveautomation.com/u/AkikRanade)\
**Post date:** [September 22, 2017, 11:16am UTC](https://forum.inductiveautomation.com/t/unable-to-apply-sql-query-binding-to-chart-bar-chart-and-easy-chart/15422/6 "2017-09-22T11:16:30Z")

</div>

I tried applying the Category chart but the extrapolated data is not what I wanted. Its inaccurate.

---

<div class="post-metadata">

**Author:** ![AkikRanade](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@AkikRanade](https://forum.inductiveautomation.com/u/AkikRanade)\
**Post date:** [September 22, 2017, 11:25am UTC](https://forum.inductiveautomation.com/t/unable-to-apply-sql-query-binding-to-chart-bar-chart-and-easy-chart/15422/7 "2017-09-22T11:25:38Z")

</div>

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/a7e4e49a9824110fbd188af3456866b9503ee2ea.png)

The dataset looks something like this. This contains hourly consumption of KWh values wherein 00:00:00 shows consumption for the hour from 00:00 to 01:00, in 01:00:00 for 01:00 to 02:00 and so on.  
The dataset is dependent on date selection via popup calendar where binding has been created to extract 24-hour data for the selected date.  
Bar Chart is unable to pick this dataset & shows blank chart.

---

<div class="post-metadata">

**Author:** ![carolina\_elfeky](https://avatars.discourse-cdn.com/v4/letter/c/8baadc/32.png) [@carolina\_elfeky](https://forum.inductiveautomation.com/u/carolina_elfeky)\
**Post date:** [September 22, 2017, 12:04pm UTC](https://forum.inductiveautomation.com/t/unable-to-apply-sql-query-binding-to-chart-bar-chart-and-easy-chart/15422/8 "2017-09-22T12:04:41Z")

</div>

So, I made a table with part of your data, I bound the chart data to the table data property.

Under the chart properties, be sure to change these two things.  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/e15507a43bfc03794a55073ca1f022cab2691b96.png)

Under the chart customizers\>\>X-axis tab create a new axis that is a category type  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/ccc3e102d401c5d164720b7de0e2e49383730888.png)

Under the chart customizer\>\>Dataset Properties change the X axis to your category axis and the Renderer to either “Category Line/Shape Renderer” or “Category Bar Renderer”

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6cd127ce90aff54df4c17daab70c6d4a1879ab2c.png)

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6b01eb327f516f3ebd23556df6dee3f0b5208117.png)

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/e2e7d14c74cb4abd35264e3673e9b01bffb5ab4e.png)

Hope this helps and is what you were looking to do.

---

<div class="post-metadata">

**Author:** ![carolina\_elfeky](https://avatars.discourse-cdn.com/v4/letter/c/8baadc/32.png) [@carolina\_elfeky](https://forum.inductiveautomation.com/u/carolina_elfeky)\
**Post date:** [September 22, 2017, 12:23pm UTC](https://forum.inductiveautomation.com/t/unable-to-apply-sql-query-binding-to-chart-bar-chart-and-easy-chart/15422/9 "2017-09-22T12:23:00Z")

</div>

Looking at your data though, you could also go with an X-axis of the date type. Just be sure to change back to XY Plot under the chart properties and change your renderer to the appropriate type. Good luck!

---

<div class="post-metadata">

**Author:** ![AkikRanade](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@AkikRanade](https://forum.inductiveautomation.com/u/AkikRanade)\
**Post date:** [September 23, 2017, 1:25pm UTC](https://forum.inductiveautomation.com/t/unable-to-apply-sql-query-binding-to-chart-bar-chart-and-easy-chart/15422/10 "2017-09-23T13:25:47Z")

</div>

It did help. Thanx a lot. But then I 'll have to configure a table in every mimic in the hindsight since data is being picked from table component itself and NOT directly from mySQL?  
Also how to bind x-axis to my Popup Calendar’s startDate and endDate custom properties such that on basis of date selected, the chart should automatically populate with 24-hour data of hourly interval. Also I only want to show recorded time in hours i.e. 01:00, 02:00… till 23:00 because entire datetime label eats up a lot of space and is of no use as such.
