mirror of
https://github.com/SARL-PACIFIC-ERP/odoo-sh-test.git
synced 2025-06-25 09:32:22 +00:00
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
/** @odoo-module **/
|
|
|
|
import { loadJS } from "@web/core/assets";
|
|
import { getColor } from "@web/core/colors/colors";
|
|
import { Component, onWillStart, useRef, onMounted, onWillUnmount } from "@odoo/owl";
|
|
|
|
export class Piechart extends Component {
|
|
static template = "awesome_dashboard.Piechart";
|
|
static props = {
|
|
label: String,
|
|
data: Object,
|
|
};
|
|
|
|
setup() {
|
|
this.canvasRef = useRef("canvas");
|
|
onWillStart(() => loadJS(["/web/static/lib/Chart/Chart.js"]));
|
|
onMounted(() => {
|
|
this.renderChart();
|
|
});
|
|
onWillUnmount(() => {
|
|
this.chart.destroy();
|
|
});
|
|
}
|
|
|
|
renderChart() {
|
|
const labels = Object.keys(this.props.data);
|
|
const data = Object.values(this.props.data);
|
|
const color = labels.map((_, index) => getColor(index));
|
|
this.chart = new Chart(this.canvasRef.el, {
|
|
type: "pie",
|
|
data: {
|
|
labels: labels,
|
|
datasets: [
|
|
{
|
|
label: this.props.label,
|
|
data: data,
|
|
backgroundColor: color,
|
|
},
|
|
],
|
|
},
|
|
});
|
|
}
|
|
|
|
|
|
} |