File: graphics.rst

package info (click to toggle)
xhtml2pdf 0.2.17%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,412 kB
  • sloc: python: 12,740; makefile: 247; xml: 24
file content (61 lines) | stat: -rw-r--r-- 1,543 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Graphs in canvas
################

Canvas in xhtml2pdf have different types of printings, when you have to build graphs you have to
set `type="graph"`, also it's important set width and height.

Canvas tag allows create, customize, and add charts to the story context that PDF receive for its creation.
It needs to be a graph type canvas, also width and height properties can be changed.

Charts available are:

- Vertical Bar `verticalbar`
- Horizontal Bar `horizontalbar`
- Horizontal Line `horizontalline`
- Pie `pie`
- Legend Pie `legendedPie`
- Doughnut  `doughnut`

It's necessary received a json inside the canvas with the following fields:

Required data:

- type
- data
- labels

Optional data:

- title
- legend
- x position
- y position


Please read reportlab documentation to know how object need to be created.

.. code:: html

    <canvas type="graph" width="350" height="180">
    Json Object Here
    </canvas>

For example:

.. code:: html

    <canvas type="graph" width="350" height="150">
          {
                "data": [[10, 20, 30, 40, 50, 60]],
                "labels": ["a", "b", "c", "d", "e", "f"],
                "title": {"_text": "Horizontal Bar Chart(1 Group)", "x": 290, "y": 155},
                "type": "horizontalbar",
                "x": 150, "y": 50,
                "barLabelFormat": "%2.0f",
                "bars": {"strokeColor": "#f01f34"},
                "barLabels": {"nudge": 5},
                "categoryAxis": {"strokeColor": "#f01f34"}
          }
    </canvas>

See more in examples.