就目前而言,在 Stock 中没有简单的方法可以在不覆盖一堆代码的情况下实现这一目标。有一个小 PoC,您可以在这里查看:https://jsfiddle.net/BlackLabel/5wdyuk8v/
但请记住,它仅适用于纯色(不支持不透明度)。
const types = Highcharts._modules['Extensions/Annotations/NavigationBindingsUtilities.js'].annotationsFieldsTypes;
types.color = types.backgroundColor = types.borderColor = types.stroke = types.fill = 'color';
function getType(key, value) {
const predefinedType = types[key];
let fieldType = typeof value;
if (Highcharts.defined(predefinedType)) {
fieldType = predefinedType;
}
return {
'string': 'text',
'number': 'number',
'boolean': 'checkbox',
'color': 'color' // fix
} [fieldType];
};
Highcharts.addEvent(
Highcharts._modules['Extensions/Annotations/NavigationBindings.js'],
'showPopup',
function(e) {
function traverse(options) {
for (const [key, option] of Object.entries(options)) {
if (Highcharts.isObject(option, true)) {
traverse(option);
} else if (Highcharts.isArray(option)) {
if (typeof option[1] === 'undefined') {
option[1] = getType(key, option[0]);
}
}
}
}
traverse(e.options);
}, {
order: 0
}
);