在有些使用 ECharts 库的 Angular 项目中,通常除了安装 npm 包之外,还会在 angular.json 中配置 “build.options.scripts”,将 “node_modules/echarts/dist/echarts.min.js”放入其中:

"projects": {
"<project-name>": {
"architect": {
"build": {
"options": {
//other config
"scripts": [
"node_modules/echarts/dist/echarts.min.js"
]
}
}
}
}
}

然后在需要使用的 TypeScript 单元顶部声明:

declare var echarts: any;

这样的做法看起来“不太像” TypeScript 的操作方式~

其实在使用 Angular 和 ECharts 的较新版本(ngx-echarts(ver >= 2.x),ECharts (ver >= 3.x))时,有更好的方式在 Angular 项目中引入 ECharts:

1、安装 npm 包:

 npm install echarts -S
npm install ngx-echarts -S
npm install @types/echarts -D

2、在 module (比如 app.module.ts)中引入模块:

 import { NgxEchartsModule } from 'ngx-echarts';
@NgModule({
imports: [
...,
NgxEchartsModule
],
})
export class AppModule { }

3、使用 ECharts:

 import * as echarts from "echarts";

 const echartsObject = echarts.init(document.getElementById("myChart"));

或者只导入必须的 API:

 import { init as echartsInit } from "echarts";

 const echartsObject = echartsInit(document.getElementById("myChart"));

参考

https://xieziyu.github.io/ngx-echarts/#/home
https://xieziyu.github.io/ngx-echarts/api-doc/

Angular 项目中如何使用 ECharts的更多相关文章

  1. gulp 在 angular 项目中的使用

    gulp 在 angular 项目中的使用 keyword:gulp,angularjs,ng,ngAnnotate,jshint,gulpfile 最后附完整简洁的ng项目gulpfile.js 准 ...

  2. angular项目中各个文件的作用

    原文地址 https://www.jianshu.com/p/176ea79a7101 大纲 1.对angular项目中的一些文件的概述 2.对其中一些文件的详细描述 2.1.package.json ...

  3. angular项目中遇到的问题

    一.angular项目中如何实现路由缓存 需要实现的效果,对请求的数据进行缓存,比如进入文章详情页之后点击返回,不会再调用后台数据接口:而是加载缓存中的数据,如何数据变动的情况下,可使用下拉刷新刷新页 ...

  4. 项目中是用eCharts

    1.首先在项目中引入echart.js库. <!DOCTYPE HTML> <%@page contentType="text/html; charset=UTF-8&qu ...

  5. angular项目中使用Primeng

    1.第一步把依赖添加到项目中 npm install primeng --save npm install @angular/animations --save npm install font-aw ...

  6. Angular项目中引入jQuery

    npm install --save jquery npm install @types/jquery --save 在对应的组件中引入 import * as $ from "jquery ...

  7. 在angular项目中使用bootstrap的tooltip插件时,报错Property 'tooltip' does no t exist on type 'JQuery<HTMLElement>的解决方法和过程

    在angular4的项目中需要使用bootstrap的tooltip插件. 1. 使用命令安装jQuery和bootstrap npm install bootstrap jquery --save ...

  8. angular项目中使用jquery的问题

    1.使用npm命令往项目中添加jQuery. npm install jquery --save 2.在你想要用jQuery的组件中添加. import * as $ from "jquer ...

  9. Angular项目中共享模块的实现

    创建share Modele:ng g m share import进来所有需要共享的模块都export出去, 一.共享CommonModule 暂时只有CommonModule,以后会有一些需要共享 ...

随机推荐

  1. React的diff算法(译文)

    前言  此篇文章主要是因为在看Virtual DOM(虚拟DOM)的时候看到的主要讲的是实现Virtual Dom 的diff算法,原文地址:https://calendar.perfplanet.c ...

  2. mysql配置默认字符集为UTF8mb4

    [client] default-character-set=utf8mb4 [mysqld] character-set-server = utf8mb4 collation-server = ut ...

  3. Dubbo和Zookerper的关系

    1.Dubbo的作用 Dubbo是管理中间层的工具,在业务层到数据仓库间有非常多服务的接入和服务提供者需要调度,dubbo提供一个框架解决这个问题.Dubbo基于RPC(Remote Procedur ...

  4. XCTF-web2

    这种题目是比较简单地..直接写个小脚本就行了2333 <?php $a=" a1zLbgQsCESEIqRLwuQAyMwLyq2L5VwBxqGA3RQAyumZ0tmMvSGM2Z ...

  5. Web性能优化:雅虎35条

    对web性能优化,一直知道是个很重要的方面,平时有注意到,但是对于雅虎35条是第一次听说,查了一下,发现平时都有用过,只是没有总结到一块,今天就总结一下吧. 雅虎35条: 1.[内容]尽量减少HTTP ...

  6. Spring Boot2 系列教程(十一)Spring Boot 中的静态资源配置

    当我们使用 SpringMVC 框架时,静态资源会被拦截,需要添加额外配置,之前老有小伙伴在微信上问松哥 Spring Boot 中的静态资源加载问题:"松哥,我的 HTML 页面好像没有样 ...

  7. 微信小程序尺寸单位rpx以及样式相关介绍

    rpx单位是微信小程序中css的尺寸单位,rpx可以根据屏幕宽度进行自适应.规定屏幕宽为750rpx.如在 iPhone6 上,屏幕宽度为375px,共有750个物理像素,则750rpx = 375p ...

  8. [Luogu2973][USACO10HOL]赶小猪Driving Out the Piggi…

    题目描述 The Cows have constructed a randomized stink bomb for the purpose of driving away the Piggies. ...

  9. Ubuntu使用中遇到的的一些问题

    制作ubuntu启动盘后,U盘只读. ubuntu自带的"启动盘创建器(usb-creator-gtk)"制作启动盘后,U盘只读. 打开ubuntu自带的"磁盘(hard ...

  10. s32k144 bootloader

    s32k144 bootloader升级 mcu       : s32k144 can_tool : kvaser  摘要:实现can升级app程序,现在网上大多是CAN_FD升级bootloade ...