英文:
Sunburst chart in angular using highcharts not showing different colors
问题
我正在尝试在Angular中使用Highcharts显示旭日图。图表正在显示,但问题出在颜色上。我已经提到了一个颜色数组,但图表只显示数组中的第一个颜色。有人可以帮助我找出问题在哪吗?
以下是我的代码:
this.chart = Highcharts.chart('container', {
chart: {
type: 'sunburst',
height: '100%'
},
colors: ['#2f7ed8', '#0d233a', '#8bbc21', '#910000', '#1aadce',
'#492970', '#f28f43', '#77a1e5', '#c42525', '#a6c96a'],
title: {
text: 'PSec GEARS Function Usage'
},
subtitle: {
text: 'Top 10 Functions used as % per User for the last Month'
},
credits: {
enabled: false
},
tooltip: {
headerFormat: '',
pointFormat: 'The population of <b>{point.name}</b> is <b>{point.value}</b>'
},
series: [{
type: "sunburst",
data: this.dataValues,
cursor: 'pointer',
dataLabels: {
format: '{point.name}',
filter: {
property: 'innerArcLength',
operator: '>',
value: 16
},
rotationMode: 'circular'
},
levels: [{
level: 1,
dataLabels: {
filter: {
property: 'outerArcLength',
operator: '>',
value: 64
}
}
}, {
level: 2,
colorByPoint: true
},
{
level: 3,
colorVariation: {
key: 'brightness',
to: -0.5
}
}, {
level: 4,
colorVariation: {
key: 'brightness',
to: 0.5
}
}]
}]
});
英文:
I'm trying to display a sunburst chart using Highcharts in Angular. The chart is displaying, but the problem is with the colors. I've mentioned an array of colors, but the chart only shows the very first color from the array. Can someone please help me what I'm doing wrong here?
Below is my code:
this.chart = Highcharts.chart('container', {
chart: {
type: 'sunburst',
height: '100%'
},
colors: ['#2f7ed8', '#0d233a', '#8bbc21', '#910000', '#1aadce',
'#492970', '#f28f43', '#77a1e5', '#c42525', '#a6c96a'],
title: {
text: 'PSec GEARS Function Usage'
},
subtitle: {
text: 'Top 10 Functions used as % per User for the last Month'
},
credits: {
enabled: false
},
tooltip: {
headerFormat: '',
pointFormat: 'The population of <b>{point.name}</b> is <b>{point.value}</b>'
},
series: [{
type: "sunburst",
data: this.dataValues,
cursor: 'pointer',
dataLabels: {
format: '{point.name}',
filter: {
property: 'innerArcLength',
operator: '>',
value: 16
},
rotationMode: 'circular'
},
levels: [{
level: 1,
dataLabels: {
filter: {
property: 'outerArcLength',
operator: '>',
value: 64
}
}
}, {
level: 2,
colorByPoint: true
},
{
level: 3,
colorVariation: {
key: 'brightness',
to: -0.5
}
}, {
level: 4,
colorVariation: {
key: 'brightness',
to: 0.5
}
}]
}]
});
答案1
得分: 1
你没有在你发送的代码中包含数据,所以很难说你到底做错了什么,但太阳图表中的数据结构应该如下所示:
Highcharts.chart('container', {
chart: {
type: 'sunburst'
},
colors: ['#2f7ed8', '#0d233a', '#8bbc21', '#910000', '#1aadce',
'#492970', '#f28f43', '#77a1e5', '#c42525', '#a6c96a'],
series: [{
type: "sunburst",
data: [
{
id: '0.0',
parent: '',
name: 'Main'
}, {
id: '1.1',
parent: '0.0',
name: 'A'
}, {
id: '1.2',
parent: '0.0',
name: 'B'
},
{
id: '1.3',
parent: '0.0',
name: 'C'
},
{
id: '2.1',
parent: '1.1',
name: 'A1',
value: 10
}, {
id: '2.2',
parent: '1.1',
name: 'A2',
value: 5
},
{
id: '2.3',
parent: '1.2',
name: 'B1',
value: 12
},
{
id: '2.4',
parent: '1.2',
name: 'B2',
value: 8
},
{
id: '2.5',
parent: '1.3',
name: 'C1',
value: 15
},
{
id: '2.6',
parent: '1.3',
name: 'C2',
value: 7
},
{
id: '2.7',
parent: '1.3',
name: 'C3',
value: 11
},
],
levels: [{
level: 1,
dataLabels: {
filter: {
property: 'outerArcLength',
operator: '>',
value: 64
}
}
}, {
level: 2,
colorByPoint: true
},
{
level: 3,
colorVariation: {
key: 'brightness',
to: -0.5
}
}, {
level: 4,
colorVariation: {
key: 'brightness',
to: 0.5
}
}]
}]
});
官方演示:https://www.highcharts.com/demo/sunburst
API文档:https://api.highcharts.com/highcharts/series.sunburst.data
英文:
You didn't include the data in the code you sent, so it's hard to say what exactly you're doing wrong, but the data structure in the sunburst chart should look like this:
<!-- begin snippet: js hide: false babel: false -->
<!-- language: lang-js -->
Highcharts.chart('container', {
chart: {
type: 'sunburst'
},
colors: ['#2f7ed8', '#0d233a', '#8bbc21', '#910000', '#1aadce',
'#492970', '#f28f43', '#77a1e5', '#c42525', '#a6c96a'],
series: [{
type: "sunburst",
data: [
{
id: '0.0',
parent: '',
name: 'Main'
}, {
id: '1.1',
parent: '0.0',
name: 'A'
}, {
id: '1.2',
parent: '0.0',
name: 'B'
},
{
id: '1.3',
parent: '0.0',
name: 'C'
},
{
id: '2.1',
parent: '1.1',
name: 'A1',
value: 10
}, {
id: '2.2',
parent: '1.1',
name: 'A2',
value: 5
},
{
id: '2.3',
parent: '1.2',
name: 'B1',
value: 12
},
{
id: '2.4',
parent: '1.2',
name: 'B2',
value: 8
},
{
id: '2.5',
parent: '1.3',
name: 'C1',
value: 15
},
{
id: '2.5',
parent: '1.3',
name: 'C2',
value: 7
},
{
id: '2.5',
parent: '1.3',
name: 'C3',
value: 11
},
],
levels: [{
level: 1,
dataLabels: {
filter: {
property: 'outerArcLength',
operator: '>',
value: 64
}
}
}, {
level: 2,
colorByPoint: true
},
{
level: 3,
colorVariation: {
key: 'brightness',
to: -0.5
}
}, {
level: 4,
colorVariation: {
key: 'brightness',
to: 0.5
}
}]
}]
});
<!-- language: lang-html -->
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/sunburst.js"></script>
<div id="container"></div>
<!-- end snippet -->
Official demo: https://www.highcharts.com/demo/sunburst <br/>
API: https://api.highcharts.com/highcharts/series.sunburst.data
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论