# How to create a simple bar graph

**URL:** <https://community.grafana.com/t/how-to-create-a-simple-bar-graph/8440>\
**Category:** General\
**Tags:** mssql\
**Created:** [June 30, 2018, 9:49pm UTC](https://community.grafana.com/t/how-to-create-a-simple-bar-graph/8440 "2018-06-30T21:49:12Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![gauravpurohit](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@gauravpurohit](https://community.grafana.com/u/gauravpurohit)\
**Post date:** [June 30, 2018, 9:49pm UTC](https://community.grafana.com/t/how-to-create-a-simple-bar-graph/8440/1 "2018-06-30T21:49:12Z")

</div>

Hi Team,

Its first time I am trying to execute sql query in grafana.  
My query is quite simple as I am looking for bar chart between number of user login w.rt. to date.  
So I have selected dashboard-\> graph -\> edit and pasted my query ,but its showing error  
“Found no column named time”.  
I want to see a bar graph (user login w.rt. to date).  
Current Login\_Time is in format of mm/dd/yyyy so I need to convert this into only date format and create a graph.  
SELECT  
[USER\_ID]  
,[LOGIN\_TIME]  
FROM [database].[dbo].[table]

I have gone through many links and tried few of them but unsuccessful.  
The below 2 solution which is provided on support side:  
now() as time\_sec – \> error mssql: ‘now’ is not a recognized built-in function name.  
\_\_timeGroup(“GMT\_CREATED”, ‘24h’, 0),-\> erro mssql: ‘\_\_timeGroup’ is not a recog

Kindly guide me .

Thanks,

---

<div class="post-metadata">

**Author:** ![anon34853223](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@anon34853223](https://community.grafana.com/u/anon34853223)\
**Post date:** [July 2, 2018, 7:25am UTC](https://community.grafana.com/t/how-to-create-a-simple-bar-graph/8440/3 "2018-07-02T07:25:36Z")

</div>

You’ve specified that you’re using mysql, but based on the errors you receive it looks like you’re using the mssql datasource?

---

<div class="post-metadata">

**Author:** ![gauravpurohit](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@gauravpurohit](https://community.grafana.com/u/gauravpurohit)\
**Post date:** [July 2, 2018, 9:01pm UTC](https://community.grafana.com/t/how-to-create-a-simple-bar-graph/8440/4 "2018-07-02T21:01:15Z")

</div>

Thanks !!!  
After applying suggested changes by you I am getting below error

mssql: Incorrect syntax near ‘\>’.

---

<div class="post-metadata">

**Author:** ![gauravpurohit](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@gauravpurohit](https://community.grafana.com/u/gauravpurohit)\
**Post date:** [July 2, 2018, 9:02pm UTC](https://community.grafana.com/t/how-to-create-a-simple-bar-graph/8440/5 "2018-07-02T21:02:10Z")

</div>

Thanks for the response !!!  
Yes, I am using mssql as datasource and querying it directly.

---

<div class="post-metadata">

**Author:** ![sivaprasad](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@sivaprasad](https://community.grafana.com/u/sivaprasad)\
**Post date:** [July 3, 2018, 6:50am UTC](https://community.grafana.com/t/how-to-create-a-simple-bar-graph/8440/6 "2018-07-03T06:50:31Z")

</div>

send me the exact query what u have used .

---

<div class="post-metadata">

**Author:** ![gauravpurohit](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@gauravpurohit](https://community.grafana.com/u/gauravpurohit)\
**Post date:** [July 3, 2018, 8:07am UTC](https://community.grafana.com/t/how-to-create-a-simple-bar-graph/8440/7 "2018-07-03T08:07:34Z")

</div>

SELECT  
[USER\_ID]  
,$\_\_timeFilter(time) as time\_sec  
FROM [mydb].[dbo].[loginuser]

where “USER\_ID” and “time” are colom names of the table “loginuser”  
mydb is the database name.

---

<div class="post-metadata">

**Author:** ![sivaprasad](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@sivaprasad](https://community.grafana.com/u/sivaprasad)\
**Post date:** [July 3, 2018, 8:56am UTC](https://community.grafana.com/t/how-to-create-a-simple-bar-graph/8440/8 "2018-07-03T08:56:03Z")

</div>

SELECT time ,

USER\_ID

FROM loginuser;

It would get expected result .

![](https://us1.discourse-cdn.com/grafana/original/2X/2/2485d26919316b1d80aa60f5ca8e2cb5bc0275fe.jpg)

---

<div class="post-metadata">

**Author:** ![gauravpurohit](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@gauravpurohit](https://community.grafana.com/u/gauravpurohit)\
**Post date:** [July 3, 2018, 10:59am UTC](https://community.grafana.com/t/how-to-create-a-simple-bar-graph/8440/9 "2018-07-03T10:59:38Z")

</div>

Thanks Siva but now I am getting Found no column named time.

---

<div class="post-metadata">

**Author:** ![sivaprasad](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@sivaprasad](https://community.grafana.com/u/sivaprasad)\
**Post date:** [July 3, 2018, 11:34am UTC](https://community.grafana.com/t/how-to-create-a-simple-bar-graph/8440/10 "2018-07-03T11:34:32Z")

</div>

Hey Gaurav

that’s your table column which has date and time ,

example: your table has a two columns datetime and userid

garfana query: select datetime as time\_sec , count(userid) as Total from your table ;

this I the pattern , max of metrics includes time series , so please go through basics

regards

Siva

![](https://us1.discourse-cdn.com/grafana/original/2X/2/2485d26919316b1d80aa60f5ca8e2cb5bc0275fe.jpg)

---

<div class="post-metadata">

**Author:** ![thachnv92](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/thachnv92/32/4183_2.png) [@thachnv92](https://community.grafana.com/u/thachnv92)\
**Post date:** [July 4, 2018, 5:35am UTC](https://community.grafana.com/t/how-to-create-a-simple-bar-graph/8440/11 "2018-07-04T05:35:39Z")

</div>

Hi @gauravpurohit

I think you should check connection to database, If you Press Save and Test =\> Database Connection OK =\> Done.

 ![image](https://us1.discourse-cdn.com/grafana/original/2X/a/a4ceeb669e46cb47a668ab4c5fe1815c9aec9d30.jpg)

The database user you specify when you add the data source should only be granted SELECT permissions on the specified database & tables you want to query. Grafana does not validate that the query is safe. The query could include any SQL statement.

```
 CREATE USER 'grafanaReader' IDENTIFIED BY 'password';
 GRANT SELECT ON mydatabase.mytable TO 'grafanaReader';

```

Refer to: [MySQL data source | Grafana documentation](http://docs.grafana.org/features/datasources/mysql/)

This is my query:

> `SELECT USER_ID, time from loginuser;`

 ![image](https://us1.discourse-cdn.com/grafana/original/2X/a/aaa31852d9d706ca8930552c1a4650b98001363a.png)

---

<div class="post-metadata">

**Author:** ![gauravpurohit](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@gauravpurohit](https://community.grafana.com/u/gauravpurohit)\
**Post date:** [July 8, 2018, 1:23pm UTC](https://community.grafana.com/t/how-to-create-a-simple-bar-graph/8440/12 "2018-07-08T13:23:51Z")

</div>

Thanks All I have manged to fix it 😀

---

<div class="post-metadata">

**Author:** ![meenu](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@meenu](https://community.grafana.com/u/meenu)\
**Post date:** [August 21, 2018, 6:26pm UTC](https://community.grafana.com/t/how-to-create-a-simple-bar-graph/8440/13 "2018-08-21T18:26:01Z")

</div>

Hi,

I am facing the same issue connecting MySQL to grafana. I am not able to create a bar graph - time series in grafana. I have the following fields in my table - id, location, name, serial\_number, manufacturer, model\_id, className, os\_version, operational\_status, dns\_domain, last\_discovered, ip\_address.

SELECT \_id, location, name, serial\_number, manufacturer, model\_id, className, os\_version, operational\_status, dns\_domain, last\_discovered, ip\_address  
FROM cmdb\_server

I want to create a graph using these columns. The last\_discovered is a string data type so I used the following query to create a graph, but no luck! Can you please guide me.

SELECT  
str\_to\_date(last\_discovered, ‘%m/%d/%Y %H:%i:%s’) as time\_sec,  
\_id as value,  
classname as metric  
FROM cmdb\_server  
WHERE $\_\_timeFilter(last\_discovered)  
ORDER BY last\_discovered ASC

I am not sure if I am using the correct value or metric and do not know what to use for value and metric. We are not targeting a specific report for now, for test purpose you can pick any column from here which will suit the query best to help me out! Thanks.

---

<div class="post-metadata">

**Author:** ![anon80964540](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@anon80964540](https://community.grafana.com/u/anon80964540)\
**Post date:** [January 13, 2021, 4:40pm UTC](https://community.grafana.com/t/how-to-create-a-simple-bar-graph/8440/14 "2021-01-13T16:40:27Z")

</div>


