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

zrfyljdw  于 2024-01-07  发布在  Chart.js
关注(0)|答案(1)|浏览(314)

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

  1. odoo.define('web.PieChart', function (require) {
  2. "use strict";
  3. /**
  4. * This widget render a Pie Chart. It is used in the dashboard view.
  5. */
  6. var core = require('web.core');
  7. var Domain = require('web.Domain');
  8. var viewRegistry = require('web.view_registry');
  9. var Widget = require('web.Widget');
  10. var widgetRegistry = require('web.widget_registry');
  11. const { loadLegacyViews } = require("@web/legacy/legacy_views");
  12. var qweb = core.qweb;
  13. var PieChart = Widget.extend({
  14. className: 'o_pie_chart',
  15. xmlDependencies: ['/web/static/src/legacy/xml/chart.xml'],
  16. /**
  17. * @override
  18. * @param {Widget} parent
  19. * @param {Object} record
  20. * @param {Object} node node from arch
  21. */
  22. init: function (parent, record, node) {
  23. this._super.apply(this, arguments);
  24. var modifiers = node.attrs.modifiers;
  25. var domain = record.domain.concat(
  26. Domain.prototype.stringToArray(modifiers.domain || '[]'));
  27. var arch = qweb.render('web.PieChart', {
  28. modifiers: modifiers,
  29. title: node.attrs.title || modifiers.title || modifiers.measure,
  30. });
  31. var pieChartContext = JSON.parse(JSON.stringify(record.context));
  32. delete pieChartContext.graph_mode;
  33. delete pieChartContext.graph_measure;
  34. delete pieChartContext.graph_groupbys;
  35. this.subViewParams = {
  36. modelName: record.model,
  37. withButtons: false,
  38. withControlPanel: false,
  39. withSearchPanel: false,
  40. isEmbedded: true,
  41. useSampleModel: record.isSample,
  42. mode: 'pie',
  43. };
  44. this.subViewParams.searchQuery = {
  45. context: pieChartContext,
  46. domain: domain,
  47. groupBy: [],
  48. timeRanges: record.timeRanges || {},
  49. };
  50. this.viewInfo = {
  51. arch: arch,
  52. fields: record.fields,
  53. viewFields: record.fieldsInfo.dashboard,
  54. };
  55. },
  56. /**
  57. * Instantiates the pie chart view and starts the graph controller.
  58. *
  59. * @override
  60. */
  61. willStart: async function () {
  62. var self = this;
  63. const _super = this._super.bind(this, ...arguments);
  64. await loadLegacyViews({ rpc: this._rpc.bind(this) });
  65. var def1 = _super();
  66. var SubView = viewRegistry.get('graph');
  67. var subView = new SubView(this.viewInfo, this.subViewParams);
  68. var def2 = subView.getController(this).then(function (controller) {
  69. self.controller = controller;
  70. return self.controller.appendTo(document.createDocumentFragment());
  71. });
  72. return Promise.all([def1, def2]);
  73. },
  74. /**
  75. * @override
  76. */
  77. start: function () {
  78. this.$el.append(this.controller.$el);
  79. return this._super.apply(this, arguments);
  80. },
  81. /**
  82. * Call `on_attach_callback` for each subview
  83. *
  84. * @override
  85. */
  86. on_attach_callback: function () {
  87. this.controller.on_attach_callback();
  88. },
  89. });
  90. widgetRegistry.add('pie_chart', PieChart);
  91. return PieChart;
  92. });

字符串

35g0bw71

35g0bw711#

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

  • 示例:*
  1. /* @odoo-module */
  2. import { patch } from "@web/core/utils/patch";
  3. const GraphView = require('web.GraphView');
  4. import { GraphRenderer } from "@web/views/graph/graph_renderer";
  5. const viewRegistry = require("web.view_registry");
  6. const LegacyGraphRenderer = viewRegistry.map.graph.prototype.config.Renderer;
  7. patch(LegacyGraphRenderer.prototype, 'formatValue', {
  8. _formatValue(value, allIntegers = true) {
  9. return GraphRenderer.prototype.formatValue(value, allIntegers);
  10. }
  11. });

字符串

展开查看全部

相关问题