# `Cardbox.Fude`
[🔗](https://github.com/hattoriai/cardbox/blob/v0.1.0/lib/cardbox/fude.ex#L2)

A collection as a Fude chart: a view's records grouped and counted, or
summed, in the database, and drawn by Fude.

    <Cardbox.Fude.chart id="budget" cardbox={MyApp.Cardbox} collection={@collection} view={@view} />

The view is a saved `Cardbox.View` of type `chart`, whose options say
what it draws:

  * `kind` - `bar`, `line`, `area`, `pie`, `donut` or `number`;
  * `x` - the field of the groups (not for a `number`): a select, a
    status, a person, a checkbox, a text, a number or a date;
  * `unit` - for a date, `day`, `month` or `year`;
  * `y` - `count` (the default), or `%{"sum" => field}` (or `mean`,
    `min`, `max`) of a number field;
  * `color` - a second field, whose groups are the bars' colours or
    the lines;
  * `title` - the chart's title, the view's name unless given.

    Box.save_view(projects, %{
      name: "Budget by status",
      type: "chart",
      options: %{kind: "bar", x: "Status", y: %{sum: "Budget"}, color: "Priority"}
    })

One `GROUP BY` through the view's query reads the groups, not the
records: a chart of fifty thousand records reads a few rows. Choices
are in their order, as a board shows them, and a currency number is
formatted in its currency.

# `build`

```elixir
@spec build(module(), Cardbox.Collection.t(), Cardbox.View.t(), keyword()) ::
  {:ok, Fude.Chart.t()} | {:error, Cardbox.Error.t()}
```

The `Fude.Chart` of a chart view, its data read from the database.
`opts`: `:people` (`%{id, name}`, for a person's groups), and those of
a query (`:me`, `:time_zone`, `:now`).

# `chart`

A chart of a view's records.
## Attributes

* `id` (`:string`) (required)
* `cardbox` (`:atom`) (required) - your Cardbox module.
* `collection` (`Cardbox.Collection`) (required)
* `view` (`Cardbox.View`) (required) - a view of type `chart`.
* `people` (`:list`) - `%{id, name}`, for a person field's groups. Defaults to `[]`.
* `me` (`:any`) - Defaults to `nil`.
* `time_zone` (`:string`) - Defaults to `nil`.
* Global attributes are accepted. Supports all globals plus: `["height", "locale", "table", "export", "class"]`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
