Graph View
Graph views provide a graphical view of the data, in the form of Bar chart, Pie chart, and Line chart. The graph view is a collection of all records in the model, which are generally visualized in the form of bars, pies, and lines.
The default type of graph is a pie chart, to change it to a bar chart just specify the type inside field in graph tag.
For Example create graph view in view model.
<record model="ir.ui.view" id="excredit_graph_view">
<field name="name">excredit.graph</field>
<field name="model">library_basic.excredit</field>
<field name="arch" type="xml">
<graph string="Borrower books">
<field name="borrower"/>
<field name="borrowers_count" type="measure"/>
</graph>
</field>
</record>
After added that code and here will disassemble and explanation about the code that has been described above.
Inside the tag <graph>
<graph string="Borrower books">
<field name="borrower"/>
<field name="borrowers_count" type="measure"/>
</graph>
Name of 'borrower' inside the <field> is get from data in model.py that get from Res User model and the name of 'borrowers_count' it also get from model.py
After add code in view xml don't fordet to add in action opening views on model like:
<field name="view_mode">tree,form,calendar,graph</field>
Add 'graph' inside tag <field></field>
After add code in view.xml and then continue to code in model.py, it must be added to show data in view.xml
borrower = fields.Many2one(string='Borrower', comodel_name='res.users')
borrowers_count = fields.Integer(string="Jumlah Buku Yang Dipinjam", compute='_get_borrowers_count')
books_ids = fields.Many2many(comodel_name="library_basic.library_basic", string="Borrowed Books")
After added code above and than create new code that depends on 'books_ids' which is in it connected to the other models in this example connected to 'library_basic' to fetch the data contained on it.
@api.depends('books_ids')
def _get_borrowers_count(self):
for r in self:
r.borrowers_count = len(r.books_ids)
Method _get_borrowers_count is called from inside borrowers_count.
r.borrowers_count is filled with the amount of data in a particular model and to display the data in that model in views page.
When everything is finished adding, then there will be an icon on the top right in the view model like:
After the icon appears and when clicked on the icon it will display the grap view
Inside the graphic page view there are several types of the graph itself such as Line Chart, Pie Chart and also Bar Chart:
The following are related resources regarding the xml code described above, click here.
Conclusion
Odoo supports several views such as tree view, form view, list view, Kanban view, pivot view, calendar view etc. Graph views provide a graphical view of the data, in the form of Bar chart, Pie chart, and Line chart. Its root element is <graph>.