5# How to Create Graph View in Odoo

Bar Chart, Line Chart, and Pie Chart Tutorial

Muhammad Abdullah Arif
4 min readJan 28, 2025

--

In this comprehensive tutorial, you will learn how to create and customize graph views in Odoo, including bar charts, line charts, and pie charts. Additionally, we will explore different test cases, supported graphs, and useful operations for various scenarios.

What is Graph View in Odoo?

Graph view in Odoo is a powerful visualization tool that allows users to represent data in graphical formats such as bar charts, line charts, and pie charts. It provides an interactive way to analyze data trends, summaries, and patterns directly within Odoo’s interface.

How to Create Graph View in Odoo?

To create a graph view in Odoo, follow these steps:

  1. Define the XML View:
<record id="view_graph_example" model="ir.ui.view">     
<field name="name">Example Graph View</field>
<field name="model">model.name</field>
<field name="arch" type="xml">
<graph string="Example Graph" type="bar">
<field name="field_x" type="row"/>
<field name="field_y" type="measure"/>
</graph>
</field>
</record>
  1. Add the View to an Action: Link the graph view to an action in your module for accessibility.
  2. Customize as Needed: Modify fields and settings based on the type of graph and use case.

How Many Types of Graphs Are Available in Odoo?

Odoo supports the following graph types:

  1. Bar Chart: Ideal for comparing quantities across categories.
  2. Line Chart: Best for showing trends over time.
  3. Pie Chart: Suitable for displaying proportions or percentages.

These graph types can be defined in the type attribute of the <graph> tag.

What Are Measures in Graph View?

In Odoo graph views, measures represent the numerical fields used for computation or aggregation (e.g., sum, average, count). These fields are defined using the type="measure" attribute in the graph view XML.

How to Change the Format of Date and Datetime Fields?

To customize the date or datetime field format in graph views:

  1. Use Odoo’s date_format or datetime_format attributes in the XML.
  2. Define specific formatting in the backend using Python.
  3. Ensure the user’s timezone is accounted for using pytz.

How to Change the Default Graph in Odoo?

Set the default graph type in the type attribute of the <graph> tag, such as type="bar", type="line", or type="pie".

How to Set Default Measure in Graph View?

Define the default measure by marking the field with type="measure". For example:

<field name="sales" type="measure" default="1"/>

This ensures the measure is preselected when the graph loads.

How to Set Default Date or Datetime Field with Different Formats?

Set a default date or datetime field in the graph view by:

  1. Using the default attribute in the <field> tag.
  2. Applying the desired date format in the backend using Python.
  3. Ensuring compatibility with the user’s timezone and locale.

How to Order the Current Graph View by Ascending or Descending Order?

You can specify the sorting order of the graph view by:

  1. Adding an order attribute to the <graph> tag in XML.
  2. Implementing ordering logic in the model’s Python methods.

Example:

<graph string="Example Graph" type="bar" order="field_y desc">

How to Stash or Unstash in the Backend?

Stashing and unstashing in Odoo’s backend involves managing state changes for records, often linked to temporary storage or filtering. To implement this:

  1. Define a stash/unstash button in the form view.
  2. Implement a method in the model to handle the logic for stashing or unstashing records.

Example Python Code:

@api.model
def stash_record(self):
self.write({'stashed': True})
def unstash_record(self):
self.write({'stashed': False})

This guide covered essential aspects of creating and customizing graph views in Odoo, providing insights into various scenarios and configurations. With these tips, you can enhance your Odoo applications and deliver meaningful data visualizations.

Ready to see how Odoo ERP can transform your business? Get in touch today to schedule a demo or explore customized solutions tailored to your industry.

Click on the link below to discover a wealth of knowledge and explore a variety of engaging topics.

Medium Profile: Muhammad Abdullah Arif — Medium

Stay Up-to-Date with Muhammad Abdullah Arif’s Latest Publications — Subscribe Now! (medium.com)

If you wish to offer your support, kindly click on the link below to treat me to a coffee! ☕️😊

https://www.buymeacoffee.com/smuhabdullah

I wish you all the best in your future endeavours.

--

--

Muhammad Abdullah Arif
Muhammad Abdullah Arif

Written by Muhammad Abdullah Arif

Python developer. The facts are the facts but opinions are my own.

No responses yet