highcharts - Highcharts 负值柱形图底部半径
问题描述
我有包含正值和负值柱形图的柱形图,我只需要为正负图给出边界半径顶部。但是,如果我尝试为负柱形图添加边界半径顶部,则它不起作用。请让我知道如何在 react js 中使用 highcharts 为负柱形图提供唯一的边界半径顶部。
例如,在提供的图像中,对于负值,我希望边框半径为 -5%。对于正值,我希望边框半径位于条形顶部。
解决方案
我准备了一个自定义代码,在列的底部为正值添加所需的边界半径 - 在顶部,对于负值。
$(function() {
'use strict';
(function(factory) {
if (typeof module === 'object' && module.exports) {
module.exports = factory;
} else {
factory(Highcharts);
}
}(function(Highcharts) {
(function(H) {
H.wrap(H.seriesTypes.column.prototype, 'translate', function(proceed) {
const options = this.options;
const topMargin = options.topMargin || 0;
const bottomMargin = options.bottomMargin || 0;
proceed.call(this);
H.each(this.points, function(point) {
console.log(point)
if (options.customRadius) {
const w = point.shapeArgs.width;
const h = point.shapeArgs.height;
const x = point.shapeArgs.x;
const y = point.shapeArgs.y;
let radiusTopLeft,
radiusTopRight,
radiusBottomRight,
radiusBottomLeft;
if (point.y > 0) {
radiusTopLeft = H.relativeLength(options.customRadius, w);
radiusTopRight = H.relativeLength(options.customRadius, w);
radiusBottomLeft = 0;
radiusBottomRight = 0;
} else {
radiusTopLeft = 0;
radiusTopRight = 0;
radiusBottomRight = H.relativeLength(options.customRadius, w);
radiusBottomLeft = H.relativeLength(options.customRadius, w);
}
const maxR = Math.min(w, h) / 2
radiusTopLeft = radiusTopLeft > maxR ? maxR : radiusTopLeft;
radiusTopRight = radiusTopRight > maxR ? maxR : radiusTopRight;
radiusBottomRight = radiusBottomRight > maxR ? maxR : radiusBottomRight;
radiusBottomLeft = radiusBottomLeft > maxR ? maxR : radiusBottomLeft;
point.dlBox = point.shapeArgs;
point.shapeType = 'path';
point.shapeArgs = {
d: [
'M', x + radiusTopLeft, y + topMargin,
'L', x + w - radiusTopRight, y + topMargin,
'C', x + w - radiusTopRight / 2, y, x + w, y + radiusTopRight / 2, x + w, y + radiusTopRight,
'L', x + w, y + h - radiusBottomRight,
'C', x + w, y + h - radiusBottomRight / 2, x + w - radiusBottomRight / 2, y + h, x + w - radiusBottomRight, y + h + bottomMargin,
'L', x + radiusBottomLeft, y + h + bottomMargin,
'C', x + radiusBottomLeft / 2, y + h, x, y + h - radiusBottomLeft / 2, x, y + h - radiusBottomLeft,
'L', x, y + radiusTopLeft,
'C', x, y + radiusTopLeft / 2, x + radiusTopLeft / 2, y, x + radiusTopLeft, y,
'Z'
]
};
}
});
});
}(Highcharts));
}));
演示:http: //jsfiddle.net/BlackLabel/okn8qhdb/
推荐阅读
- reactjs - 我想在 React Native 中为我的子类添加 CSS
- reactjs - 期望 `onChange` 侦听器是一个函数,而不是获得 `object` 类型的值
- pandas - Python:检索重复名称之间的最大值并将csv文件中的相应数据输出为字典格式
- c# - .NET 2.0 IL 优化 while 循环
- javascript - “ null 不是一个对象(评估'this.state.array')”
- javascript - 如何停止事件(mineflayer)
- python - 无法在 mininet 上运行 python 程序。没有错误
- java - 使用 Hibernate 的表值更改问题
- python-3.x - 如何用 Cartopy 绘制洋流
- reactjs - 清除超时/间隔是否必须在“useEffect”反应挂钩内?