我想使用Angular 8集成Highcharts中的组织结构图。
但是,当我尝试使用以下代码实现时,会在系列类型
中抛出错误import { Component, OnInit } from '@angular/core';
import * as Highcharts from 'highcharts';
import HighchartsSankey from "highcharts/modules/sankey";
import HighchartsOrganization from "highcharts/modules/organization";
import HighchartsExporting from "highcharts/modules/exporting";
HighchartsSankey(Highcharts);
HighchartsOrganization(Highcharts);
HighchartsExporting(Highcharts);
@Component({
selector: 'organization-users',...
})
export class OrganizationComponent implements OnInit {
ngOnInit() {
Highcharts.chart({
chart: {
height: 600,
inverted: true
},
title: {
text: 'Highcharts Org Chart'
},
series: [{
**type: 'organization',**
keys: ['from', 'to'],
data: [
['Shareholders', 'Board'],
['Board', 'CEO'],
['CEO', 'CTO'],
['CEO', 'CPO']
],...
答案 0 :(得分:2)
呈现组织结构图可能很棘手。
如果要在其中使用任何其他模块,我们必须先向Highcharts注册,如他们建议的in this article here。
由于我们需要使用也依赖于organization
的{{1}}模块,因此我们首先必须向sankey
注册,然后向sankey
注册高图。这就是以下几行:
organization
完成后,渲染图表将非常简单。
在这里,尝试一下:
declare var require: any;
let sankey = require("highcharts/modules/sankey");
let organization = require("highcharts/modules/organization");
sankey(Highcharts);
organization(Highcharts);
在您的模板中:
import { Component, ViewChild } from "@angular/core";
import * as Highcharts from "highcharts";
declare var require: any;
let sankey = require("highcharts/modules/sankey");
let organization = require("highcharts/modules/organization");
sankey(Highcharts);
organization(Highcharts);
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
@ViewChild("orgChartContainer", { static: false }) orgChartContainer;
ngOnInit() {}
ngAfterViewInit() {
//Organization chart starts
/* Highcharts.chart(this.barChartContainer.nativeElement, {
// Created pie chart using Highchart
chart: {
type: "column"
},
xAxis: {
type: "category"
},
series: [
{
name: "TOTAL chart",
data: [
{
name: "Planned",
y: 30,
drilldown: "planned"
}
]
}
],
//Drill Downs
drilldown: {
series: [
{
name: "Planned Drill Down",
id: "planned",
data: [["plan A", 55.03], ["plan B", 15.83]]
}
]
}
}); */
Highcharts.chart(this.orgChartContainer.nativeElement, {
chart: {
height: 600,
inverted: true
},
title: {
text: "Highcharts Org Chart"
},
accessibility: {
point: {
descriptionFormatter: function(point) {
var nodeName = point.toNode.name,
nodeId = point.toNode.id,
nodeDesc =
nodeName === nodeId ? nodeName : nodeName + ", " + nodeId,
parentDesc = point.fromNode.id;
return (
point.index + ". " + nodeDesc + ", reports to " + parentDesc + "."
);
}
}
},
series: [
{
type: "organization",
name: "Highsoft",
keys: ["from", "to"],
data: [
["Shareholders", "Board"],
["Board", "CEO"],
["CEO", "CTO"],
["CEO", "CPO"],
["CEO", "CSO"],
["CEO", "CMO"],
["CEO", "HR"],
["CTO", "Product"],
["CTO", "Web"],
["CSO", "Sales"],
["CMO", "Market"]
],
levels: [
{
level: 0,
color: "silver",
dataLabels: {
color: "black"
},
height: 25
},
{
level: 1,
color: "silver",
dataLabels: {
color: "black"
},
height: 25
},
{
level: 2,
color: "#980104"
},
{
level: 4,
color: "#359154"
}
],
nodes: [
{
id: "Shareholders"
},
{
id: "Board"
},
{
id: "CEO",
title: "CEO",
name: "Grethe Hjetland",
image:
"https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132317/Grethe.jpg"
},
{
id: "HR",
title: "HR/CFO",
name: "Anne Jorunn Fjærestad",
color: "#007ad0",
image:
"https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132314/AnneJorunn.jpg",
column: 3,
offset: "75%"
},
{
id: "CTO",
title: "CTO",
name: "Christer Vasseng",
column: 4,
image:
"https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12140620/Christer.jpg",
layout: "hanging"
},
{
id: "CPO",
title: "CPO",
name: "Torstein Hønsi",
column: 4,
image:
"https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12131849/Torstein1.jpg"
},
{
id: "CSO",
title: "CSO",
name: "Anita Nesse",
column: 4,
image:
"https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132313/Anita.jpg",
layout: "hanging"
},
{
id: "CMO",
title: "CMO",
name: "Vidar Brekke",
column: 4,
image:
"https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/13105551/Vidar.jpg",
layout: "hanging"
},
{
id: "Product",
name: "Product developers"
},
{
id: "Web",
name: "Web devs, sys admin"
},
{
id: "Sales",
name: "Sales team"
},
{
id: "Market",
name: "Marketing team"
}
],
colorByPoint: false,
color: "#007ad0",
dataLabels: {
color: "white"
},
borderColor: "white",
nodeWidth: 65
}
],
tooltip: {
outside: true
},
exporting: {
allowHTML: true,
sourceWidth: 800,
sourceHeight: 600
}
});
//Organization chart ends
}
}
这是您推荐的Sample Demo。