| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Technical Name |
highcharts_widget |
| Versions | 10.0 13.0 14.0 16.0 |
Highcharts Graph Widget
To include highcharts's graph into forms's views...
How to use
In your model you need create a function that return a valid Highchart's graph data, for example:
# -*- coding: utf-8 -*-
from odoo import api, models
class TestGraph(models.Model):
_name = 'highcharts_widget.test_graph'
_description = 'Testing graph feature...'
@api.multi
def compute_graph_data(self):
self.ensure_one()
return {
'chart': {
'plotBackgroundColor': 'white',
'plotBorderWidth': '0',
},
'title': {
'text': 'Browser market shares at a specific website, 2014'
},
'tooltip': {
'pointFormat': '{series.name}: {point.percentage:.1f}%'
},
'plotOptions': {
'pie': {
'allowPointSelect': 'true',
'cursor': 'pointer',
'dataLabels': {
'enabled': 'false'
},
'showInLegend': 'true'
}
},
'series': [{
'type': 'pie',
'name': 'Browser share',
'data': [
['Firefox', 45.0],
['IE', 26.8],
{
'name': 'Chrome',
'y': 12.8,
'sliced': 'true',
'selected': 'true'
},
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]
}]
}
In the xml definition you should write something like that:
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record id="highcharts_widget_test_form_view" model="ir.ui.view">
<field name="name">highcharts_widget_test_form_view</field>
<field name="model">highcharts_widget.test_graph</field>
<field name="arch" type="xml">
<form>
<sheet>
<widget id="test_model_graph"
model="highcharts_widget.test_graph"
method="compute_graph_data"
type="graph_widget"
/>
</sheet>
</form>
</field>
</record>
<record id="highcharts_widget_test_action" model="ir.actions.act_window">
<field name="name">Graph Test</field>
<field name="res_model">highcharts_widget.test_graph</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
</record>
<menuitem name="Graph Test"
id="highcharts_widget_test_menu_item"
action="highcharts_widget_test_action"
sequence="1"/>
</data>
</odoo>
Alejandro Cora Gonzalez
alek.cora.glez@gmail.com
Please log in to comment on this module