Здесь у меня есть рабочее решение в стиле Angular 9.
Установка: "sunburst-chart": "^1.8.0"
и, если хотите, также "d3": "^5.15.0"
.
import { Component, OnInit } from '@angular/core';
import Sunburst from 'sunburst-chart';
import * as d3 from 'd3';
@Component({
selector: 'app-sunburst',
templateUrl: './sunburst.component.html',
styleUrls: ['./sunburst.component.scss']
})
export class SunburstComponent implements OnInit {
loading: boolean;
@ViewChild('sbChart', { static: true }) sbChartEl: ElementRef;
constructor() {}
ngOnInit() {
this.loading = true;
const color = d3.scaleOrdinal(d3.schemePaired);
const sbdata = {
name: 'main',
color: 'magenta',
children: [
{
name: 'a',
size: 1
},
{
name: 'b',
children: [
{
name: 'ba',
size: 1
},
{
name: 'bb',
children: [
{
name: 'bba',
size: 1
},
{
name: 'bbb',
size: 1
}
]
}
]
}
]
};
Sunburst()
.data(sbdata)
.size('size')
.height(500)
.showLabels(false)
.tooltipContent((d, node) => `Size: <i>${node.value}</i>`)
//.color(d => color(d.name))(document.getElementById('sbChart'));
.color(d => color(d.name))(this.sbChartEl.nativeElement);
this.loading = false;
}
}
Файл sunburst.component.html
:
<div [hidden]="loading">
<div id="sbChart" #sbChart></div>
</div>