ChartJS 如何删除工具提示饼图Odoo 15中的小数?

zrfyljdw  于 11个月前  发布在  Chart.js
关注(0)|答案(1)|浏览(195)

This tooltip is displayed when the mouse cursor hovers over a particular data pointThis is the widgetproperty_type_id = fields.Many2one("estate.property.type", string="Property Type")property_ids = fields.One2many("estate.property", "property_type_id", string="Properties")您在工具提示中看到的带有两个零的图像中的数字是属性的计数,就像它是一个浮点数一样。如何删除小数?我发现odoo使用chart.js 2.9.3,但我不知道如何修改JS来进行我想要的更改。我试图扩展此代码以删除小数点但是我不能我已经看到了谷歌前4页上的所有链接,我看了大量与Odoo,Pie Charts和Chart.js相关的YouTube视频,我在WhatsApp和Telegram群组中寻求帮助,什么也没有。
this code(below) is in

odoo.define('web.PieChart', function (require) {
"use strict";

/**
 * This widget render a Pie Chart. It is used in the dashboard view.
 */

var core = require('web.core');
var Domain = require('web.Domain');
var viewRegistry = require('web.view_registry');
var Widget = require('web.Widget');
var widgetRegistry = require('web.widget_registry');
const { loadLegacyViews } = require("@web/legacy/legacy_views");

var qweb = core.qweb;

var PieChart = Widget.extend({
    className: 'o_pie_chart',
    xmlDependencies: ['/web/static/src/legacy/xml/chart.xml'],

    /**
     * @override
     * @param {Widget} parent
     * @param {Object} record
     * @param {Object} node node from arch
     */
    init: function (parent, record, node) {
        this._super.apply(this, arguments);

        var modifiers = node.attrs.modifiers;
        var domain = record.domain.concat(
            Domain.prototype.stringToArray(modifiers.domain || '[]'));
        var arch = qweb.render('web.PieChart', {
            modifiers: modifiers,
            title: node.attrs.title || modifiers.title || modifiers.measure,
        });

        var pieChartContext = JSON.parse(JSON.stringify(record.context));
        delete pieChartContext.graph_mode;
        delete pieChartContext.graph_measure;
        delete pieChartContext.graph_groupbys;

        this.subViewParams = {
            modelName: record.model,
            withButtons: false,
            withControlPanel: false,
            withSearchPanel: false,
            isEmbedded: true,
            useSampleModel: record.isSample,
            mode: 'pie',
        };
        this.subViewParams.searchQuery = {
            context: pieChartContext,
            domain: domain,
            groupBy: [],
            timeRanges: record.timeRanges || {},
        };

        this.viewInfo = {
            arch: arch,
            fields: record.fields,
            viewFields: record.fieldsInfo.dashboard,
        };
    },
    /**
     * Instantiates the pie chart view and starts the graph controller.
     *
     * @override
     */
    willStart: async function () {
        var self = this;
        const _super = this._super.bind(this, ...arguments);
        await loadLegacyViews({ rpc: this._rpc.bind(this) });
        var def1 = _super();

        var SubView = viewRegistry.get('graph');
        var subView = new SubView(this.viewInfo, this.subViewParams);
        var def2 = subView.getController(this).then(function (controller) {
            self.controller = controller;
            return self.controller.appendTo(document.createDocumentFragment());
        });
        return Promise.all([def1, def2]);
    },
    /**
     * @override
     */
    start: function () {
        this.$el.append(this.controller.$el);
        return this._super.apply(this, arguments);
    },
    /**
     * Call `on_attach_callback` for each subview
     *
     * @override
     */
    on_attach_callback: function () {
        this.controller.on_attach_callback();
    },
});

widgetRegistry.add('pie_chart', PieChart);

return PieChart;

});

字符串

35g0bw71

35g0bw711#

您可以覆盖旧版图形渲染器_formatValue函数,以使用新的图形渲染器formatValue函数,该函数将自动删除尾随零

  • 示例:*
/* @odoo-module */

import { patch } from "@web/core/utils/patch";

const GraphView = require('web.GraphView');
import { GraphRenderer } from "@web/views/graph/graph_renderer";
const viewRegistry = require("web.view_registry");
const LegacyGraphRenderer = viewRegistry.map.graph.prototype.config.Renderer;

patch(LegacyGraphRenderer.prototype, 'formatValue', {
    _formatValue(value, allIntegers = true) {
        return GraphRenderer.prototype.formatValue(value, allIntegers);
    }
});

字符串

相关问题