Show a chart on a dashboard
A chart region draws one total per group of rows: columns, bars or a line. The server draws it
as SVG, so it needs no JavaScript. This guide adds charts to the dashboard of a club. It
assumes a members table with a status column (the values active, passive and
honorary), a joined_on date, and a fee_group reference. The club example application has
them.
Count rows per month
Section titled “Count rows per month”- Add a
chartregion to the dashboard page. Name the table, then a label. - Write
x:with a time bucket of a date column.month(joined_on)groups the members by the month ofjoined_on. - Write
y: count. Each bucket shows the number of rows in it. - Write
last:with the number of months to draw. A chart of time must say how far back it reaches.
chart of members "Members joined per month" { x: month(joined_on) y: count last: 12}The chart draws 12 columns. The last one is the month that holds today. A month in which nobody joined is drawn as 0. It is not skipped.
The months are cut in the time zone of the application. On the club’s dashboard, that is
Europe/Berlin. A member who joined at 22:30 UTC on 31 March is counted in April there. To cut
the months in another zone, set timezone: on the page. See
Set the time zone.
Split each month by status
Section titled “Split each month by status”- Write
by:with anenumcolumn. Use a column with at most 4 values. - Add
access:to show the chart to the board only. - Add
empty:for the text that shows when no member matches.
chart of members "Members joined per month" { access: board x: month(joined_on) y: count by: status last: 12 empty: "Nobody has joined in the last year."}Each month is now a stack of three parts, one per status, in the order that the enum declares
them. A legend names the parts. The parts differ by colour (blue, purple and amber for three parts)
and the third and fourth also by texture (a diagonal hatch and dots), so they stay apart on a
printout and for a reader who cannot tell colours apart. Write stack: false to put the parts side by side.
Open Table: Members joined per month under the chart to read the same numbers as a table. Use it with a keyboard or a screen reader.
The chart counts the rows that the board may read. A row filter on the page or an application
scope narrows the count in the same way as it narrows a report. A member in a gone state is
not counted.
Draw a total per reference
Section titled “Draw a total per reference”x: can be a ref column. Each target is then one bucket, and the chart ranks the targets.
chart of members "Members per fee group" { x: fee_group y: count top: 8}The chart draws the 8 fee groups with the most members as horizontal bars. Each label is the display of the fee group. If there are more groups, their members are added into one last bar, “Other”.
To total a number instead of counting rows, use sum. This example is for a line_items table
with a kind enum, a unit_price in money and an int quantity. A sum needs empty:,
because SQL has no answer for a sum of no rows:
chart of line_items "Revenue by kind" { x: kind y: sum(unit_price) { weight: quantity empty: zero }}weight: multiplies each price by the quantity before the total is added. empty: zero draws
0 for a kind with no rows. With min and max, use empty: null when “no rows” is not the
value 0. The chart then draws no mark for that bucket.
A decimal column works the same way. For a duration_hours of type decimal(2),
y: sum(duration_hours) { empty: zero } draws 1,500.25 under English notation and 1.500,25
under German notation. The axis, the titles and the table behind the chart all show two places.
sum, min and max of a decimal keep its places.
Check the limits
Section titled “Check the limits”- A page holds at most 4 charts.
by:takes at most 4 values,last:at most 60 buckets, andtop:at most 12 targets.- A chart cannot use a
sensitivecolumn, because it shows totals without a grant. yreads a storedint,decimalormoneycolumn. A computed column and an aggregate column are not charted.- There is no
avg. The language has no division.
The compiler names the line and the repair for each of these. See
chart for every property, and
Project status for what a chart cannot do yet.