angular - 类型“SeriesOrganizationDataLabelsOptionsObject []”上不存在获取错误属性“nodeFormatter”
问题描述
我正在尝试以角度实现 HighCharts。这是组织图表。但我收到了类似的错误
Property 'nodeFormatter' does not exist on type 'SeriesOrganizationDataLabelsOptionsObject[]'
.ts 文件
export class OrganisationComponent implements OnInit {
chartRef: any;
public options: any = {
chart: {
height: 300,
inverted: true
},
title: {
useHTML: true,
text: "Org Chart"
},
series: [
{
type: "organization",
name: "Highsoft",
linkColor: '#ccc',
linkLineWidth: "2",
keys: ["from", "to"],
cursor: "pointer",
colorByPoint: false,
color: "#b3e6ff",
data: [
{ from: 'TM',to: 'D1'},
{ from: 'TM',to: 'D2'},
{ from: 'TM',to: 'D3'},
],
levels: [
{level: 0},{level: 1},{level: 2}
],
dataLabels: {
color: 'white',
nodeFormatter: function () {
// Call the default renderer
var html = Highcharts.defaultOptions
.plotOptions
.organization
.dataLabels
.nodeFormatter
.call(this);
// Do some modification
html = html.replace(
'<h4 style="',
'<h4 style="font-style: italic;'
);
return html;
}
},
nodes: [
{
id: "TM",
icon: "account_circle",
name: "Team Lead",
info: " TM info",
events: {
click: event => {
this.changeLinkColor(event.point.level, event);
}
},
},
{
id: "D1",
icon: "account_circle",
name: "Developer 1",
info: " D1 info",
events: {
click: event => {
this.changeLinkColor(event.point.level, event);
}
}
},
{
id: "D2",
icon: "account_circle",
name: "Developer 2",
info: " D2 info",
events: {
click: event => {
this.changeLinkColor(event.point.level, event);
}
}
},
{
id: "D3",
icon: "account_circle",
name: "Developer 3",
info: " D3 info",
events: {
click: event => {
this.changeLinkColor(event.point.level, event);
}
}
},
],
}
],
tooltip: {
enabled: false,
}
};
ngOnInit() {
this.drawChart();
}
changeLinkColor(level, event) {
// Reset all dataLables
this.resetAllActiveClasses()
// Apply link color
this.options.series[0].levels.forEach(levelRow => {
if (levelRow.level === level) {
levelRow.linkColor = "#007ad0";
} else {
levelRow.linkColor = "#666666";
}
});
// Apply css class
this.setActiveClass(event.point.id, event.point.linksFrom, true)
this.chartRef.update(this.options)
}
setActiveClass(id, childsNodes, isParent = false){
const className = isParent === true ? 'parent-active' : 'child-active'
this.options.series[0].nodes.forEach(
(node) =>{
if(node.id === id) {
node.dataLabels = {
className:className
}
}
}
)
if(childsNodes.length>0){
childsNodes.forEach(
(childNode) =>{
if(childNode.toNode.linksFrom.length>0){
console.log(childNode.to, " has child")
this.setActiveClass(childNode.to, childNode.toNode.linksFrom)
} else {
this.setActiveClass(childNode.to, [])
}
}
)
}
}
resetAllActiveClasses(){
this.options.series[0].nodes.forEach(
(node) =>{
node.dataLabels = {
className:''
}
}
)
}
drawChart() {
this.chartRef = Highcharts.chart("container", this.options);
}
}
由于此功能在文档本身中给出
工作链接 https://stackblitz.com/edit/angular-bar-highcharts-bnom1n
文档链接
https://api.highcharts.com/highcharts/series.organization.dataLabels.nodeFormatter
解决方案
dataLabels 是一个数组,您将其视为一个对象:
var html = Highcharts.defaultOptions .plotOptions .organization .dataLabels .nodeFormatter .call(this);
应该是这样的:
var html = Highcharts.defaultOptions .plotOptions .organization .dataLabels[0] .nodeFormatter .call(this);
Ps抱歉格式化-在移动设备上
推荐阅读
- r - ggplot2注释中文字高度的单位是什么?
- r - 为具有连续值的渐变图创建 R ggplot2 离散调色板
- sql - 如何创建查询以将多个项目与一个项目匹配
- c# - JavaLang 没有这样的方法错误 Xamarin 表单
- video - Gstreamer Multifilesrc循环短视频
- php - 使用 PHP Curl 或 file_get_content 下载 Instagram 图片
- c# - Gstreamer-sharp 1.16 Playbin“无法查询当前持续时间。”
- c++ - 以这种特殊的方式获得重复排列
- python - 如何在基于类的视图中使用先前的输入初始化 django 表单?
- singlestore - 如何在memsql中使用光标变成手?