diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index 906eedb303..2e47b391a2 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -1041,7 +1041,10 @@ export default { field_fixed: 'Fixed', line_type_dotted: 'Dotted', value_can_not_empty: 'Value can not be empty', - value_error: 'Value illegal' + value_error: 'Value illegal', + threshold: 'Threshold', + threshold_range: 'Range', + gauge_threshold_format_error: 'Format Error' }, dataset: { sheet_warn: 'There are multiple sheet pages, and the first one is extracted by default', diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index 372a8d3ec7..932281f454 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -1041,7 +1041,10 @@ export default { field_fixed: '固定值', line_type_dotted: '點', value_can_not_empty: '值不能為空', - value_error: '值必須為數值' + value_error: '值必須為數值', + threshold: '閾值', + threshold_range: '閾值區間', + gauge_threshold_format_error: '格式錯誤' }, dataset: { sheet_warn: '有多個 Sheet 頁,默認抽取第一個', diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index c73b300abc..d1b0837762 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -1044,7 +1044,10 @@ export default { field_fixed: '固定值', line_type_dotted: '点', value_can_not_empty: '值不能为空', - value_error: '值必须为数值' + value_error: '值必须为数值', + threshold: '阈值', + threshold_range: '阈值区间', + gauge_threshold_format_error: '格式错误' }, dataset: { sheet_warn: '有多个 Sheet 页,默认抽取第一个', diff --git a/frontend/src/views/chart/chart/chart.js b/frontend/src/views/chart/chart/chart.js index d7d62bcdee..1640bb5963 100644 --- a/frontend/src/views/chart/chart/chart.js +++ b/frontend/src/views/chart/chart/chart.js @@ -244,6 +244,9 @@ export const DEFAULT_FUNCTION_CFG = { sliderShow: false, sliderRange: [0, 10] } +export const DEFAULT_THRESHOLD = { + gaugeThreshold: '' +} // chart config export const BASE_BAR = { title: { diff --git a/frontend/src/views/chart/chart/gauge/gauge.js b/frontend/src/views/chart/chart/gauge/gauge.js index 616d0b8561..7bcef2c0ec 100644 --- a/frontend/src/views/chart/chart/gauge/gauge.js +++ b/frontend/src/views/chart/chart/gauge/gauge.js @@ -49,6 +49,34 @@ export function baseGaugeOption(chart_option, chart) { value: chart.data.series[0].data[0] } chart_option.series[0].data.push(y) + // threshold + if (chart.senior) { + const range = [] + const senior = JSON.parse(chart.senior) + const threshold = JSON.parse(JSON.stringify(senior.threshold)) + if (threshold.gaugeThreshold && threshold.gaugeThreshold !== '') { + const arr = threshold.gaugeThreshold.split(',') + for (let i = 0; i < arr.length; i++) { + const ele = arr[i] + const p = parseInt(ele) / 100 + range.push([p, hexColorToRGBA(customAttr.color.colors[i % 9], customAttr.color.alpha)]) + } + + range.push([1, hexColorToRGBA(customAttr.color.colors[arr.length % 9], customAttr.color.alpha)]) + chart_option.series[0].axisLine = { + lineStyle: { + color: range + } + } + + chart_option.series[0].itemStyle = { + color: 'auto' + } + chart_option.series[0].progress = { + show: false + } + } + } } } // console.log(chart_option); diff --git a/frontend/src/views/chart/chart/gauge/gauge_antv.js b/frontend/src/views/chart/chart/gauge/gauge_antv.js index 1fe0979e30..a927c859ec 100644 --- a/frontend/src/views/chart/chart/gauge/gauge_antv.js +++ b/frontend/src/views/chart/chart/gauge/gauge_antv.js @@ -33,11 +33,39 @@ export function baseGaugeOptionAntV(plot, container, chart, action) { labelContent = false } } + const per = (parseFloat(data) / parseFloat(max)) + + const range = [0] + let index = 0 + let flag = false + let hasThreshold = false + + if (chart.senior) { + const senior = JSON.parse(chart.senior) + const threshold = JSON.parse(JSON.stringify(senior.threshold)) + if (threshold.gaugeThreshold && threshold.gaugeThreshold !== '') { + hasThreshold = true + const arr = threshold.gaugeThreshold.split(',') + for (let i = 0; i < arr.length; i++) { + const ele = arr[i] + const p = parseInt(ele) / 100 + range.push(p) + if (!flag && per <= p) { + flag = true + index = i + } + } + if (!flag) { + index = arr.length + } + } + } + range.push(1) // options const options = { theme: theme, - percent: (parseFloat(data) / parseFloat(max)), + percent: per, startAngle: startAngel, endAngle: endAngel, appendPadding: getPadding(chart), @@ -52,6 +80,24 @@ export function baseGaugeOptionAntV(plot, container, chart, action) { // lineCap: 'round' // } } + if (hasThreshold) { + options.range = { + color: theme.styleSheet.paletteQualitative10, + ticks: range + } + options.indicator = { + pointer: { + style: { + stroke: theme.styleSheet.paletteQualitative10[index % 9] + } + }, + pin: { + style: { + stroke: theme.styleSheet.paletteQualitative10[index % 9] + } + } + } + } // 开始渲染 if (plot) { diff --git a/frontend/src/views/chart/components/senior/Threshold.vue b/frontend/src/views/chart/components/senior/Threshold.vue new file mode 100644 index 0000000000..b180ca18c6 --- /dev/null +++ b/frontend/src/views/chart/components/senior/Threshold.vue @@ -0,0 +1,123 @@ + + + + + + 0, + + ,100 + + + 阈值设置,决定仪表盘区间颜色,为空则不开启阈值,范围(0-100),仅限整数,且逐级递增 + + 例如:输入 30,70;表示:分为3段,分别为[0,30],(30,70],(70,100] + + + + + + + + + + + + diff --git a/frontend/src/views/chart/group/Group.vue b/frontend/src/views/chart/group/Group.vue index 613c4d3e61..bc49ce2d06 100644 --- a/frontend/src/views/chart/group/Group.vue +++ b/frontend/src/views/chart/group/Group.vue @@ -309,7 +309,7 @@ import { DEFAULT_YAXIS_EXT_STYLE, DEFAULT_BACKGROUND_COLOR, DEFAULT_SPLIT, - DEFAULT_FUNCTION_CFG + DEFAULT_FUNCTION_CFG, DEFAULT_THRESHOLD } from '../chart/chart' export default { @@ -767,7 +767,8 @@ export default { }) view.senior = JSON.stringify({ functionCfg: DEFAULT_FUNCTION_CFG, - assistLine: [] + assistLine: [], + threshold: DEFAULT_THRESHOLD }) view.stylePriority = 'view' // 默认样式优先级视图 view.xaxis = JSON.stringify([]) diff --git a/frontend/src/views/chart/view/ChartEdit.vue b/frontend/src/views/chart/view/ChartEdit.vue index 146713344b..dcb629782c 100644 --- a/frontend/src/views/chart/view/ChartEdit.vue +++ b/frontend/src/views/chart/view/ChartEdit.vue @@ -813,11 +813,11 @@ - + {{ $t('chart.senior_cfg') }} @@ -825,12 +825,15 @@ - + {{ $t('chart.analyse_cfg') }} - + + + + @@ -1039,7 +1042,7 @@ import { DEFAULT_LABEL, DEFAULT_LEGEND_STYLE, DEFAULT_SIZE, - DEFAULT_SPLIT, + DEFAULT_SPLIT, DEFAULT_THRESHOLD, DEFAULT_TITLE_STYLE, DEFAULT_TOOLTIP, DEFAULT_XAXIS_STYLE, @@ -1084,9 +1087,11 @@ import DimensionExtItem from '@/views/chart/components/drag-item/DimensionExtIte import PluginCom from '@/views/system/plugin/PluginCom' import FunctionCfg from '@/views/chart/components/senior/FunctionCfg' import AssistLine from '@/views/chart/components/senior/AssistLine' +import Threshold from '@/views/chart/components/senior/Threshold' export default { name: 'ChartEdit', components: { + Threshold, AssistLine, FunctionCfg, DimensionExtItem, @@ -1174,7 +1179,8 @@ export default { }, senior: { functionCfg: DEFAULT_FUNCTION_CFG, - assistLine: [] + assistLine: [], + threshold: DEFAULT_THRESHOLD }, customFilter: [], render: 'antv', @@ -1756,6 +1762,11 @@ export default { this.calcStyle() }, + onThresholdChange(val) { + this.view.senior.threshold = val + this.calcStyle() + }, + showDimensionEditFilter(item) { this.dimensionItem = JSON.parse(JSON.stringify(item)) this.dimensionFilterEdit = true