I am newbie. Just installed grafana and trying to build a report out of Mysql data. I have the following query and data. I would like to create a stacked bar chart with one bar for each day.
`SELECT DATE_FORMAT(from_unixtime(created_at), ` `"%Y-%m-%d"` `) day,`
`SUM(IF (replace(JSON_EXTRACT(custom_info, ` `'$.Environment'` `), ` `'\"'` `, ` `''` `) in (` `'Production'` `,` `'Contingency'` `), ` `1` `, ` `0` `)) as Production,`
`SUM(IF (replace(JSON_EXTRACT(custom_info, ` `'$.Environment'` `), ` `'\"'` `, ` `''` `) not in (` `'Production'` `,` `'Contingency'` `), ` `1` `, ` `0` `)) as NonProd,`
`count(*) CNT`
`from sigs`
`where DATE_FORMAT(from_unixtime(created_at), ` `"%Y-%m-%d"` `) > DATE_SUB(NOW(), INTERVAL ` `30` `DAY) and`
`(replace(JSON_EXTRACT(custom_info, ` `'$.SupportGroupList'` `), ` `'\"'` `, ` `''` `) like ` `'%WASSUPP%'` `or replace(JSON_EXTRACT(custom_info, ` `'$.SupportGroupList'` `), ` `'\"'` `, ` `''` `) like ` `'%MIDDLEWARE%'` `)`
`group by day`
Data:
±-----------±-----------±--------±----+
| day | Production | NonProd | CNT |
±-----------±-----------±--------±----+
| 2019-01-28 | 3 | 2 | 5 |
| 2019-01-29 | 1 | 2 | 3 |
| 2019-01-30 | 1 | 6 | 7 |
| 2019-01-31 | 5 | 4 | 9 |
| 2019-02-01 | 1 | 3 | 4 |
| 2019-02-02 | 7 | 3 | 10 |
| 2019-02-03 | 40 | 0 | 40 |
| 2019-02-04 | 12 | 1 | 13 |
| 2019-02-05 | 7 | 1 | 8 |
| 2019-02-06 | 3 | 7 | 10 |
| 2019-02-07 | 6 | 2 | 8 |
| 2019-02-08 | 12 | 4 | 16 |
| 2019-02-09 | 4 | 1 | 5 |
| 2019-02-10 | 41 | 0 | 41 |
| 2019-02-11 | 3 | 1 | 4 |
| 2019-02-12 | 2 | 2 | 4 |
| 2019-02-13 | 6 | 1 | 7 |
| 2019-02-14 | 2 | 0 | 2 |
| 2019-02-15 | 6 | 0 | 6 |
| 2019-02-16 | 9 | 0 | 9 |
| 2019-02-18 | 2 | 3 | 5 |
| 2019-02-20 | 6 | 0 | 6 |
| 2019-02-21 | 2 | 1 | 3 |
| 2019-02-22 | 16 | 5 | 21 |
| 2019-02-23 | 8 | 2 | 10 |
| 2019-02-24 | 31 | 0 | 31 |
| 2019-02-25 | 7 | 1 | 8 |
| 2019-02-26 | 11 | 6 | 17 |
Trying to figure how to modify the default query to get the report I need.
SELECT
UNIX_TIMESTAMP(<time_column>) as time_sec,
<value column> as value,
<series name column> as metric
FROM <table name>
WHERE $__timeFilter(time_column)
ORDER BY <time_column> ASC