有耐心的可以看看,没耐心的直接滑倒最后加上h: 1就行
需求 页面有两个highcharts图 一个3d饼图和3d不同高度圆环图,
不同高度圆环图的核心代码:
// 修改3d饼图绘制过程
const each = HighCharts.each;
const round = Math.round;
const cos = Math.cos;
const sin = Math.sin;
const deg2rad = Math.deg2rad;
HighCharts.wrap(
HighCharts.seriesTypes.pie.prototype,
"translate",
function (proceed) {
proceed.apply(this, [].slice.call(arguments, 1));
// Do not do this if the chart is not 3D
if (!this.chart.is3d()) {
return;
}
const series = this;
const chart = series.chart;
const options = chart.options;
const seriesOptions = series.options;
const depth = seriesOptions.depth || 0;
const options3d = options.chart.options3d;
const alpha = options3d.alpha;
const beta = options3d.beta;
var z = seriesOptions.stacking
? (seriesOptions.stack || 0) * depth
: series._i * depth;
z += depth / 2;
if (seriesOptions.grouping !== false) {
z = 0;
}
each(series.data, function (point) {
const shapeArgs = point.shapeArgs;
var angle;
point.shapeType = "arc3d";
var ran = point.options.h;
shapeArgs.z = z;
shapeArgs.depth = depth * 0.75 + ran;
shapeArgs.alpha = alpha;
shapeArgs.beta = beta;
shapeArgs.center = series.center;
shapeArgs.ran = ran;
angle = (shapeArgs.end + shapeArgs.start) / 2;
point.slicedTranslation = {
translateX: round(
cos(angle) * seriesOptions.slicedOffset * cos(alpha * deg2rad)
),
translateY: round(
sin(angle) * seriesOptions.slicedOffset * cos(alpha * deg2rad)
),
};
});
}
);
(function (H) {
H.wrap(
HighCharts.SVGRenderer.prototype,
"arc3dPath",
function (proceed) {
// Run original proceed method
const ret = proceed.apply(this, [].slice.call(arguments, 1));
ret.zTop = (ret.zOut + 0.5) / 100;
return ret;
}
);
})(HighCharts);
具体就不贴代码了,可以自己去网上找
第二个不同高度圆环图在修改3d饼图绘制过程时直接作用在引入的highcharts实例上,
因为已经重置了3d饼图绘制过程,所以同页面的饼图会被覆盖掉高度,就会变扁

只需要给饼图的data增加参数h: 1就可以了
下图是官网找的数据,自己在处理数据的时候直接加上就行了,


1万+

被折叠的 条评论
为什么被折叠?



