# Creating a Bar or Pie chart allowing user to select different time periods

**URL:** <https://forum.inductiveautomation.com/t/creating-a-bar-or-pie-chart-allowing-user-to-select-different-time-periods/84797>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 25, 2024, 11:20pm UTC](https://forum.inductiveautomation.com/t/creating-a-bar-or-pie-chart-allowing-user-to-select-different-time-periods/84797 "2024-01-25T23:20:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sibusiso\_Moyo](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@Sibusiso\_Moyo](https://forum.inductiveautomation.com/u/Sibusiso_Moyo)\
**Post date:** [January 25, 2024, 11:20pm UTC](https://forum.inductiveautomation.com/t/creating-a-bar-or-pie-chart-allowing-user-to-select-different-time-periods/84797/1 "2024-01-25T23:20:31Z")

</div>

I have transactional data, and I want to plot number of visitors by department. So I have DATE, DEPT and USER. I want count users by department and then visualize this using a bar chat.

The query I'd use for binding could be:  
SELECT DEPT, COUNT(USER) AS VISITORS  
FROM DATASET  
WHERE DATE BETWEEN 'START' AND 'END'  
GROUP BY DEPT

I want the ability to plot these bar charts (or pie charts) for any time frame the user decides. So if I have a data set for a year, I want to be able to plot a bar chat for any selected dates.

I can do the bar chat without a time element, but I'm struggling with how to implement the aggregation when there is a time element involved. I want my query to recalculate the counts when a new date range is selected.

Any ideas of how to implement this with Perspective Components?

 ![users_dept](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/9/3945177e776e37e2db516466ebb5e78ea88f9342.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 25, 2024, 11:26pm UTC](https://forum.inductiveautomation.com/t/creating-a-bar-or-pie-chart-allowing-user-to-select-different-time-periods/84797/2 "2024-01-25T23:26:45Z")

</div>

- Put your SQL in a [Named Query]]([Named Queries - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/Named+Queries)). Create START and END query parameters of type DATE.
- On your Pie Chart data property create a query binding, use your new named query and bind the START and END parameters to your calendar values.

> **[Named Query Introduction Video at Inductive University](https://inductiveuniversity.com/videos/named-query-introduction/8.1)**
>
> Take a quick tour of the Named Query workspace.
