1
我想用Angular2开发一个web应用程序,它包含一个谷歌饼图。Angular2谷歌饼图可视化
我为饼图创建了一个指令,这里是代码。
@Directive({
selector: 'pie-chart'
})
export class PieChartDirective {
el: HTMLElement;
w: any;
private _content: any = {};
@Input()
set content(c: any) {
this._content = c;
this.draw();
}
get content() { return this._content; }
constructor(elementRef: ElementRef) {
this.w = window;
this.el = elementRef.nativeElement;
if (!this.w.google) { console.error("Google chart yuklenmedi.."); };
}
draw() {
var data = this.w.google.visualization.arrayToDataTable([
['Label', 'Value'],
['Hedef ve Üstü', this._content.hedeF_UST],
['Hedef Altı', this._content.hedeF_ALT]
]);
let options = {
"backgroundColor": '#f1f8e9',
width: '100px',
title: this._content.name,
colors: ['#088A4B', 'red'],
chartArea: {
left: "5%",
top: "20%",
height: "75%",
width: "90%"
}
};
(new this.w.google.visualization.PieChart(this.el))
.draw(data, options);
}
}
然后我用它在应用程序组件。在这之前没有问题,它适用于IE 10,11和Edge以及Chrome。但是Firefox有问题。它可视化图表视图非常小。
和
是在显示它之前绘制的图表吗? – WhiteHat
我在像 这样的组件中使用此伪指令在这种情况下,是否在绘制之前显示? @WhiteHat –
yeulucay
尝试在图表选项中设置特定宽度_和高度_作为数字 - 而不是宽度:'100px''宽度:100' - >请参阅[配置选项](https://开发人员。 google.com/chart/interactive/docs/gallery/piechart#configuration-options) – WhiteHat