diff --git a/core/core-frontend/src/views/chart/components/js/extremumUitl.ts b/core/core-frontend/src/views/chart/components/js/extremumUitl.ts index dfc029bf92..f3efd025f5 100644 --- a/core/core-frontend/src/views/chart/components/js/extremumUitl.ts +++ b/core/core-frontend/src/views/chart/components/js/extremumUitl.ts @@ -1,5 +1,5 @@ import { valueFormatter } from '@/views/chart/components/js/formatter' -import { parseJson } from '@/views/chart/components/js/util' +import { hexToRgba, parseJson } from '@/views/chart/components/js/util' import { isEmpty } from 'lodash-es' export const clearExtremum = chart => { @@ -326,7 +326,10 @@ export const createExtremumPoint = (chart, ev) => { pointElement.style.fontSize = fontSize + 'px' pointElement.style.lineHeight = fontSize + 'px' // 渐变颜色时需要获取最后一个rgba的值作为背景 - const { r, b, g, a } = getRgbaColorLastRgba(point.color) + const color = point.color.startsWith('#') + ? hexToRgba(point.color, basicStyle.alpha / 100) + : getRgbaColorLastRgba(point.color) + const { r, b, g, a } = color pointElement.style.backgroundColor = 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')' pointElement.style.color = isColorLight(point.color) ? '#000' : '#fff' pointElement.children[0]['style'].borderTopColor = diff --git a/core/core-frontend/src/views/chart/components/js/util.ts b/core/core-frontend/src/views/chart/components/js/util.ts index d5ac73c01b..27da58d6dd 100644 --- a/core/core-frontend/src/views/chart/components/js/util.ts +++ b/core/core-frontend/src/views/chart/components/js/util.ts @@ -1142,3 +1142,19 @@ export const measureText = (chart, text, font, type) => { } return 0 } + +/** + * 获取十六进制颜色值 + * @param hex + * @param alpha + */ +export const hexToRgba = (hex, alpha = 1) => { + // 去掉 # 号 + hex = hex.replace('#', '') + // 转换为 RGB 分量 + const r = parseInt(hex.slice(0, 2), 16) + const g = parseInt(hex.slice(2, 4), 16) + const b = parseInt(hex.slice(4, 6), 16) + // 返回 RGBA 格式 + return `rgba(${r}, ${g}, ${b}, ${alpha})` +}