Parcourir la source

fix: 仪表盘支持设置指标显示的小数位数

hong.yang il y a 1 an
Parent
commit
e6cf38ba67

+ 18 - 1
data-room-ui/packages/G2Plots/进度图/仪表盘.js

@@ -99,6 +99,18 @@ const setting = [
     tabName: 'custom',
     groupName: 'graph'
   },
+  {
+    label: '指标小数位',
+    // 设置组件类型
+    type: 'inputNumber',
+    // 字段
+    field: 'statistic_fixed',
+    // 对应options中的字段
+    optionField: 'statisticFixed',
+    value: 0,
+    tabName: 'custom',
+    groupName: 'graph'
+  },
   {
     label: '指标字体类型',
     // 设置组件类型
@@ -185,7 +197,11 @@ const data = [
   }
 ]
 // 配置处理脚本
-const optionHandler ='option.range.color = [option.color1, option.color2]'
+const optionHandler ='option.range.color = [option.color1, option.color2]\n' +
+  '  let fix = option.statisticFixed\n' +
+  '  option.statistic.title.formatter = ({ percent }) => `${(percent * 100).toFixed(fix)}%`'
+
+
 
 // 数据处理脚本
 const dataHandler = '// 取返回数据列表的第一项指标值\noption.percent = data[0][setting.filter(settingItem=>settingItem.field === \'percent\')[0].value]'
@@ -226,6 +242,7 @@ const option = {
   // shapeStyle: {
   //   fill: 'rgba(208,208,208,0)'
   // },
+  statisticFixed: 0,
   statistic: {
     title: {
       offsetY: 0,

+ 16 - 1
data-room-ui/packages/G2Plots/进度图/进度仪表盘.js

@@ -75,6 +75,18 @@ const setting = [
     tabName: 'custom',
     groupName: 'graph'
   },
+  {
+    label: '指标小数位',
+    // 设置组件类型
+    type: 'inputNumber',
+    // 字段
+    field: 'statistic_fixed',
+    // 对应options中的字段
+    optionField: 'statisticFixed',
+    value: 0,
+    tabName: 'custom',
+    groupName: 'graph'
+  },
   {
     label: '指标字体类型',
     // 设置组件类型
@@ -160,7 +172,9 @@ const data = [
   }
 ]
 // 配置处理脚本
-const optionHandler ='option.range.color = [option.color1, option.color2]'
+const optionHandler ='option.range.color = [option.color1, option.color2]\n' +
+  '  let fix = option.statisticFixed\n' +
+  '  option.statistic.title.formatter = ({ percent }) => `${(percent * 100).toFixed(fix)}%`'
 // 数据处理脚本
 const dataHandler = '// 取返回数据列表的第一项指标值\noption.percent = data[0][setting.filter(settingItem=>settingItem.field === \'percent\')[0].value]'
 
@@ -175,6 +189,7 @@ const option = {
   range: {
     color: ['l(0) 0:#6b74e4 1:#4391f4','#d0d0d0']
   },
+  statisticFixed: 0,
   startAngle: Math.PI,
   endAngle: 2 * Math.PI,
   indicator: null,