我正在寻找图表Javascript库来为我的角度项目创建某种顶级动态框图。任何人都可以告诉我,如果mermaid与Angular 4兼容吗? 如果有任何其他好的图表库可以使用,请告诉我。谢谢!
答案 0 :(得分:1)
它非常容易使用。
npm i mermaid
示例:
import { Component, OnInit } from "@angular/core";
import * as mermaid from "mermaid";
@Component({
selector: "MermaidTest",
template: `
<div class="mermaid">
graph LR
A-->B
</div>`
})
export class MermaidTest implements OnInit {
public ngOnInit(): void {
mermaid.initialize({
theme: "forest"
});
}
}
在这种情况下,你必须转义像{。如果您碰巧将图形内容作为字符串,则可以改为使用mermaidAPI:
import { AfterContentInit, Component, ViewChild } from "@angular/core";
import * as mermaid from "mermaid";
@Component({
selector: "MermaidTest",
template: `<div #mermaid></div>`
})
export class MermaidTestimplements AfterContentInit {
@ViewChild("mermaid")
public mermaidDiv;
public ngAfterContentInit(): void {
mermaid.initialize({
theme: "dark"
});
const element: any = this.mermaidDiv.nativeElement;
const graphDefinition = "graph TB\na-->b";
mermaid.render("graphDiv", graphDefinition, (svgCode, bindFunctions) => {
element.innerHTML = svgCode;
});
}
}
答案 1 :(得分:0)
不能说美人鱼,但建议你试试ngx-charts https://swimlane.gitbooks.io/ngx-charts/content/它确实支持Angular
答案 2 :(得分:0)
尝试也基于d3的ngx-graph,类似于ngx-chart,但专注于图,尤其是DAG https://github.com/swimlane/ngx-graph