piechart

piechart, tile type

The piechart tile displays a categorical breakdown. It expects one numeric vector and one group by clause.

Examples

table T = with
  [| as Product, as Sales |]
  [| "Shirt", 120 |]
  [| "Hat", 80 |]
  [| "Shoes", 40 |]

show piechart "Sales per product" { 1..6, 1..14 } with
  sum(T.Sales)
  group by T.Product

A color vector can assign each category a stable color. The color is aggregated at the same grain as the displayed amount: same(Sales.Color) expects one consistent color within each category group.

table Sales = with
  [| as Category, as Amount, as Color |]
  [| "Apparel", 120, "blue/600" |]
  [| "Garden", 80, "orange/600" |]
  [| "Home", 40, "green/600" |]

mix = show region { 1..6, 1..18 }

show piechart "Sales by category" { .., 1..15 in mix } with
  sum(Sales.Amount) { value { color: #[same(Sales.Color)]; unit: "$"; precision: 2 } }
  group by Sales.Category
  order by Sales.Category

Apparel is blue, Garden orange, and Home green. Their shares are one half, one third, and one sixth of total sales. The legend includes the monetary values alongside those shares. The explicit mapping keeps each category’s color attached to its name when the ordering changes.

StyleCode

In region-based dashboards, StyleCode attaches to the piechart, its series, and the category values. The value scope controls per-category colors and number formatting.

The legacy dashboard attachment points are listed below.

For generic StyleCode rules, see stylecode.

User Contributed Notes
0 notes + add a note