Angular6 引入G2
1.下载 G2包
【Angular6 引入G2】
npm install @antv/g2 --save
2. 成功安装完成之后,即可使用
import
进行引用。 import * as G2 from '@antv/g2';
注意:
- 此时会报错,找不到‘@antv/g2’模块,解决方法,随便改变文件,保存就行
- 按 es6 的规范
import * as obj from "xxx"
会将"xxx"
中所有export
导出的内容组合成一个对象返回。
HTML:
TS:
import { Component, OnInit } from '@angular/core'; import * as G2 from '@antv/g2'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { title = 'app'; data = https://www.it610.com/article/{}; chart ; graph; constructor() { } ngOnInit() { this.chartData(); } chartData() { this.data = [ { genre:'Sports', sold: 275 }, { genre: 'Strategy', sold: 115 }, { genre: 'Action', sold: 120 }, { genre: 'Shooter', sold: 350 }, { genre: 'Other', sold: 150 } ]; this.chart = new G2.Chart({ container: 'c1', // 指定图表容器 ID width : 600, // 指定图表宽度 height : 300 // 指定图表高度 }); this.chart.source(this.data); this.chart.interval().position('genre*sold').color('genre'); //渲染图表 this.chart.render(); } }
效果图:
![Angular6 引入G2](https://img.it610.com/image/info8/fdbab1aa53c44efcb68298a409edad71.jpg)
文章图片
推荐阅读
- Stream详解
- IDEA使用Maven管理项目包,缺少pom文件中引入的依赖包
- 模块和包的引入总结
- Vue组件开发之异步组件详解
- 1.前端引入jeDate日期控件
- Spring|Spring Boot parent 或者 spring-boot-dependencies引入spring boot
- 伦敦市长萨迪克汗Crossrail受挫,转进准备引入租金管控。
- 在ARKit项目如何引入一个3D模型
- ztree|ztree 拖拽
- 2018-05-29|2018-05-29 Django 模板文件引入静态文件