Hi, I want to create a bar chart in canvas with a consistent 10 bars even if there is no data for 10 bars. It is for a competition and, for example, at the beginning of the week there might not be enough data to have 10 entries yet. Because of the design I do want to display a bar chart with potentially 10 bars so all other values should be zero.
My query does a 'top 10' and might return 6 for example.
I was trying to solve this with createTable
thinking that if I create a table with 10 rows and then pipe the results from the query into it it would create some rows with data and some empty
createTable
Creates a datatable with a list of columns, and 1 or more empty rows. To populate the rows, use [mapColumn
]or [mathColumn
]
My code (based on examples in the canvas function reference)
filters group='this week'
| var_set
name=reps value={essql query="select \"sales.representative.name\" as salesRep from \"index*\" group by salesRep"}
name=revenue value={essql query="select sum(some-field) as revenue from \"index*\" "}
| createTable rowCount=10
| mapColumn name="salesRep" expression={var "reps" | getCell "salesRep"}
| mapColumn name="revenue" expression={var "revenue" | getCell "revenue"}
| render
It results in a datatable with simply 10 times the same entry, like this:
salesrep | revenue |
---|---|
John | 1000 |
John | 1000 |
John | 1000 |
John | 1000 |
John | 1000 |
John | 1000 |
John | 1000 |
John | 1000 |
John | 1000 |
John | 1000 |
So my question is: how should this createTable be used and how should it work?
thanks