如何解决AnyChart 库应该如何与 Angular 一起使用?
我正在尝试将 AnyChart 库集成到我的 Angular 11 应用程序中,但我不断收到错误消息:
类型“typeof anychart”上不存在属性“maps”。您指的是“地图”吗?
我的代码如下所示:
import {AfterViewInit,Component,OnInit,ViewChild} from '@angular/core';
import 'anychart';
@Component({
selector: 'app-map-chart',templateUrl: './map-chart.component.html',styleUrls: ['./map-chart.component.scss']
})
export class MapChartComponent implements OnInit {
@ViewChild('chartContainer') container;
chart= anychart.map()
dataSet = anychart.data.set(
[{"id":"UG.KN","value":0},{"id":"UG.JI","value":1},{"id":"UG.KU","value":2},]
);
constructor() {
// set chart title
this.chart.title("Map Title");
this.chart.choropleth(this.dataSet);// What to put here
// set geoIdField to 'id',this field contains in geo data meta properties
this.chart.geoIdField('id');
// set map color settings
// this.chart.colorScale(anychart.scales.linearColor('#deebf7','#3182bd'));
this.chart.hovered().fill('#addd8e');
this.chart.geoData(anychart.maps['uganda']);
}
ngOnInit(): void {
}
ngAfterViewInit() {
this.chart.container(this.container.nativeElement);
this.chart.draw();
}
}
有关如何解决此问题的任何指示
解决方法
您应该包含地图文件以使其工作。有关详细信息,请查看 the demo application。要启动它,请执行 npm install
和 npm run start
。
使用库在组件上方添加declare var anychart: any
解决了问题
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。