【发布时间】:2019-06-30 16:39:48
【问题描述】:
所以我希望创建一个 3d 饼图(在 Highcharts 中),其中每个切片的深度由点的值确定。问题here 应该让您对我的目标有一个很好的了解。
目前 Highcharts 仅支持系列级别的深度参数,所以我的第一个想法是制作多个系列,如下所示:#1。
1:
Highcharts.chart('container', {
chart: {
type: 'pie',
options3d: {
enabled: true,
alpha: 60
}
},
title: {
text: 'Contents of Highsoft\'s weekly fruit delivery'
},
subtitle: {
text: '3D donut in Highcharts'
},
plotOptions: {
pie: {
innerSize: 125,
depth: 60
}
},
series: [{
name: 'Delivered amount',
data: [
{ name: 'a', y: 1, val: 0.59, color: '#25683d' },
{ name: 'b', y: 1, val: 1.25, color: '#222f58' },
{ name: 'c', y: 2, val: 0.73, color: '#bebe89' },
],
depth: 45,
startAngle: 0,
endAngle: 180
}, {
data: [
{ name: 'd', y: 2, val: -0.69, color: '#900' },
{ name: 'e', y: 2, val: 0.57, color: '#a0a0a0' }
],
depth: 60,
startAngle: 180,
endAngle: 360
}]
});
<script src="https://code.highcharts.com/highcharts.js">
</script>
<script src="https://code.highcharts.com/highcharts-3d.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<div id="container" style="height: 400px"></div>
- 问题在于深度似乎保持相同的顶部参考点,而不是每个“切片”从相同 y 点开始的预期结果。
当这不起作用时,我又将所有数据存储在一个系列中,并尝试在渲染后更新 SVG 元素深度(可以在此处看到:#2。
2:
Highcharts.chart('container', {
chart: {
type: 'pie',
options3d: {
enabled: true,
alpha: 60
},
events: {
load: function() {
this.series[0].data.forEach((val, i) => {
var depth = val.graphic.attribs.depth;
val.graphic.attribs.depth = depth + (i * 10);
});
this.redraw();
}
}
},
title: {
text: 'Contents of Highsoft\'s weekly fruit delivery'
},
subtitle: {
text: '3D donut in Highcharts'
},
plotOptions: {
pie: {
innerSize: 125,
depth: 60
}
},
series: [{
name: 'Delivered amount',
data: [{
name: 'a',
y: 1,
val: 0.59,
color: '#25683d'
},
{
name: 'b',
y: 1,
val: 1.25,
color: '#222f58'
},
{
name: 'c',
y: 2,
val: 0.73,
color: '#bebe89'
},
{
name: 'd',
y: 2,
val: -0.69,
color: '#900'
},
{
name: 'e',
y: 2,
val: 0.57,
color: '#a0a0a0'
}
],
}]
});
-
再一次,深度似乎只是降低了内容,而我在翻译 (https://api.highcharts.com/class-reference/Highcharts.SVGElement#translate) 以将每个切片向上移动的尝试在保持美观的图表方面不太成功。例如:#3。
- 还值得注意的是,我必须为 y 翻译定义一个数组,这主要是反复试验的结果
3:
Highcharts.chart('container', {
chart: {
type: 'pie',
options3d: {
enabled: true,
alpha: 60
},
events: {
load: function() {
this.series[0].data.forEach((val, i) => {
var depth = val.graphic.attribs.depth;
val.graphic.attribs.depth = depth + (i * 10);
});
this.redraw();
},
redraw: function() {
var y_trans = [0, -8, -16, -25, -34];
this.series[0].data.forEach((val, i) => {
val.graphic.translate(0, y_trans[i]);
});
}
}
},
title: {
text: 'Contents of Highsoft\'s weekly fruit delivery'
},
subtitle: {
text: '3D donut in Highcharts'
},
plotOptions: {
pie: {
innerSize: 125,
depth: 60
}
},
series: [{
name: 'Delivered amount',
data: [{
name: 'a',
y: 1,
val: 0.59,
color: '#25683d'
},
{
name: 'b',
y: 1,
val: 1.25,
color: '#222f58'
},
{
name: 'c',
y: 2,
val: 0.73,
color: '#bebe89'
},
{
name: 'd',
y: 2,
val: -0.69,
color: '#900'
},
{
name: 'e',
y: 2,
val: 0.57,
color: '#a0a0a0'
}
],
}]
});
任何参考或想法将不胜感激,因为我开始碰壁了。
【问题讨论】:
标签: javascript svg highcharts