Graph view
A graph view draws one measure of a model as a bar, line or pie chart over the values of one or two fields. An addon
declares it in a view file; no code is needed. The manifest must list web in depends: graph is owned by web.
<record id="book_graph" model="ir.ui.view"> <field name="name">sample_library.book.graph</field> <field name="model">sample_library.book</field> <field name="arch" type="xml"> <graph string="Books" type="bar"> <field name="published_on" interval="year"/> <field name="book_format"/> <field name="price" type="measure"/> <field name="pages" type="measure"/> </graph> </field></record>The server admits and delivers the view through get_views (renderer web.graph); list graph in the action’s
view_mode and the web client draws it (plain SVG, no chart library) with a Graph button in the view switcher. The
user guide is docs/user/graph-view.md.
What it supports
Section titled “What it supports”| Declaration | Meaning |
|---|---|
<graph type> | bar (the default), line or pie: the chart drawn first. |
<graph stacked cumulated> | stacked (default on) stacks the series of a bar or line chart; cumulated (default off) adds the values up along the first grouping. Literal 1/0/True/False only. |
<graph order> | asc or desc (upper case is accepted and delivered in lower case): the groups are sorted by their total. Absent: in grouping order. |
<graph disable_linking> | 1 turns off opening the records of a bar or slice. |
<field name="f"/>, type="row", type="col" | A grouping. All three mean the same: the first grouping declared is the axis (the slices of a pie), the second the series. A stored boolean, char, integer, selection, many2one, date or datetime field. |
interval="month" | On a date or datetime grouping: day, week, month, quarter or year. |
<field name="f" type="measure"/> | A measure: a stored integer, float or monetary field that adds up (not sequence). Declare several; the last one is drawn first, the others are offered to switch to. With none, the chart counts records. |
The delivered root carries mode, stacked, cumulated, disable_linking and, when declared, order; each field carries
its role (group or measure), its label (string, or the field’s label) and its interval when declared.
What is refused
Section titled “What is refused”The reference ignores an unknown chart type or order and skips a field it cannot group by. Here the server refuses the view when it is read, naming the attribute, the field or the limit.
| Declared | Result |
|---|---|
type other than bar, line, pie; order other than asc, desc | refused, naming the value |
| a third grouping | refused: the chart groups by at most two fields (the axis, then the series) |
| the same field twice as a grouping, even with different intervals | refused (the reference keeps only the finest interval) |
| a text, html, float, one2many or many2many field, or a field without a column, as a grouping | refused |
interval on a field that is not a date or datetime, on a measure, or with another value | refused |
| a measure that is not a stored integer, float or monetary field, or the same measure twice | refused |
widget, invisible, options on a field; sample, cumulated_start, class, js_class on the root | refused by name |
a stacked, cumulated or disable_linking that is an expression | refused |
The bound an administrator sets
Section titled “The bound an administrator sets”web.graph_max_groups (Settings, the web addon’s panel; read by internal users, written by administrators): the most groups
one chart read may return, both groupings crossed. Default 1,000, floor 50, hard bound 20,000; a value outside them is
refused by name. The web client reads it when it opens a graph and refuses a larger answer by name rather than drawing part
of it.
Server calls
Section titled “Server calls”The chart reads its data with the grouped read the pivot already uses, formatted_read_grouping_sets (each grouping alone and
both crossed, in one call, with each group’s domain for opening its records); the graph view adds no RPC method.
In the web client
Section titled “In the web client”| Piece | Where | What it does |
|---|---|---|
| decode | addons/web/static/src/client/metadata.ts | Reads the delivered graph and graph_field nodes; an unknown mode, order or role is refused. |
| model | addons/web/static/src/client/graph.ts | readGraphView (arch and field list to a config), GraphModel (one read per change of measure, groupings or search; chart type, stacking, cumulation and order change nothing on the server), the address parameters. |
| chart | addons/web/static/src/client/graph-view.ts | mountGraph: the toolbar, the SVG chart, the legend and the data table. Colours are the --accent and --palette-1 to --palette-11 tokens, so both themes apply. |
The search’s Group By sets the groupings, at most two; with none, the arch’s are drawn. Cards of the list’s dashboard kept in the address narrow the chart as they narrow the list.
The page address keeps what differs from the arch: graph_mode (bar, line, pie), graph_measure (a field or
__count), graph_groupby (one or two field or field:interval, comma separated), graph_order (asc, desc, or
none when the arch declares an order and the user cleared it), graph_stacked and graph_cumulated (0 or 1). The
server’s address check (crates/erp-server/src/redirect.rs) admits the same shapes, so a reload of a graph never fails.
The action context keys graph_measure, graph_mode, graph_groupbys, graph_order, graph_stacked and
graph_cumulated are not read yet: declare the chart in the arch.