Skip to content

Commit

Permalink
update charts docs with group_by feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanga committed Mar 16, 2017
1 parent 948181a commit 6dfa687
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion docs/charts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,62 @@ Response
- ``html`` format response is a html, javascript and css to the chart
- ``json`` format response is the ``JSON`` data that can be passed to a charting library

Get a chart for field grouped by another field in the form
----------------------------------------------------------

- ``field_name`` - a field name in the form, for group by multiple fields
requires this to be a numeric field.
- ``group_by`` - a field name in the form to group by, if it is a comma
separated field list then the field_name will be grouped by all the fields in
the list.
- ``format`` - can be ``html`` or ``json``

.. raw:: html

<pre class="prettyprint">
<b>GET</b> /api/v1/charts/<code>{formid}</code>.<code>{format}</code>?field_name=<code>field_name</code>&group_by=<code>field1,field2</code></pre>

Example
^^^^^^^
::

curl -X GET https://api.ona.io/api/v1/charts/4240.json?field_name=age&group_by=year
curl -X GET https://api.ona.io/api/v1/charts/4240.json?field_name=age&group_by=sex,year

Response
^^^^^^^^

- ``html`` format response is a html, javascript and css to the chart
- ``json`` format response is the ``JSON`` data that can be passed to a charting library

.. raw:: json
{
"field_type": "integer",
"data_type": "numeric",
"field_xpath": "age",
"data": [
{
"mean": 45.0,
"sum": 855.0,
"year": "1880",
"sex": [
"Female"
]
},
{
"mean": 45.0,
"sum": 855.0,
"year": "1850",
"sex": [
"Female"
]
},
"field_label": "Age",
"field_name": "age",
"xform": 4240
}
Get a chart data for all fields in a form
------------------------------------------

Expand All @@ -103,4 +159,4 @@ Response

- `json` format response is the `JSON` data for each field that can be passed to a charting library


0 comments on commit 6dfa687

Please sign in to comment.