angular6.x 引入echarts
因为angular2+ 使用 ==typescript==开发,所以想要使用echarts,必须安装echarts针对angular的插件ngx-echarts。本文案列实际效果如上图。
安装ngx-echarts
npm install echarts --save
npm install ngx-echarts@3.2.0 --save
注意
- echarts >= 3.x
- angular >= 6 使用 v 3.0.0 以上版本
- angular <= 6 使用 v 2.3.1 以下版本
在项目中引入echarts
在angular.json文件中引入echarts.js
// angular.json 文件
{
...
"build":{
...
"options":{
...
"scripts":[
"node_modules/echarts/dist/echarts.min.js"
]
}
}
}
引入ngx-echarts模块
在 app.modules.ts根模块中引入 NgxEchartsModule
// app.modules.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import {NgxEchartsModule} from 'ngx-echarts'
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
NgxEchartsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
使用
app.component.ts
// app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor() {}
public chartOption={
backgroundColor: '#2c343c',
title: {
text: 'Customized Pie',
left: 'center',
top: 20,
textStyle: {
color: '#ccc'
}
},
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b} : {c} ({d}%)"
},
visualMap: {
show: false,
min: 80,
max: 600,
inRange: {
colorLightness: [0, 1]
}
},
series: [
{
name: '访问来源',
type: 'pie',
radius: '55%',
center: ['50%', '50%'],
data: [
{ value: 335, name: '直接访问' },
{ value: 310, name: '邮件营销' },
{ value: 274, name: '联盟广告' },
{ value: 235, name: '视频广告' },
{ value: 400, name: '搜索引擎' }
].sort(function(a, b) { return a.value - b.value; }),
roseType: 'radius',
label: {
normal: {
textStyle: {
color: 'rgba(255, 255, 255, 0.6)'
}
}
},
labelLine: {
normal: {
lineStyle: {
color: 'rgba(255, 255, 255, 0.3)'
},
smooth: 0.2,
length: 10,
length2: 20
}
},
itemStyle: {
normal: {
color: '#c23531',
shadowBlur: 200,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
},
animationType: 'scale',
animationEasing: 'elasticOut',
animationDelay: function(idx) {
return Math.random() * 200;
}
}
]
}
}
app.component.html
// app.component.html
<div echarts [options]="chartOption" class="chart"></div>
app.component.css
// app.component.css
.chart {
height: 400px;
}
angular6.x 引入echarts的更多相关文章
- AngularJS引入Echarts的Demo
最近要用到图表展示,想了想,还是首选Echarts,HighCharts和D3.js备用吧, 而项目中也用到了AngularJS,所以需要把Echarts引入到AngularJs中一起使用, 试了试, ...
- vue引入echarts、找不到的图表引入方法、图表中的点击事件
1.在vue-cli项目中添加webpack配置,本文引入的最新版本.在 3.1.1 版本之前 ECharts 在 npm 上的 package 是非官方维护的,从 3.1.1 开始由官方 EFE 维 ...
- vue按需引入echarts
下载安装echarts包:npm install echarts -D 一.全局引入 main.js中配置 import echarts from 'echarts' //引入echarts Vue. ...
- vue-webpack 引入echarts 注意事项
0.执行教程 https://www.cnblogs.com/goloving/p/8654176.html1.在index 中创建 div <!DOCTYPE html> <htm ...
- mpvue中按需引入echarts
大家都知道小程序文件大小不能超过2M, 在项目中引入echarts后,文件大小远远超出2M了.因为echarts文件默认是包含所有图表代码的,所以文件体积会比较大.解决办法如下: 安装 首先我们先安装 ...
- 16、vue引入echarts,划中国地图
vue引入echarts npm install echarts --save main.js引入 import echarts from 'echarts' Vue.prototype.$echar ...
- Angular6如何引入jQuery-knob
Angular6如何引入jQuery-knob 1.概述 Angular6引入jQuery变得异常简单,请参考https://blog.csdn.net/qq_35321405/article/det ...
- 【React】react项目引入echarts插件 K线图
参考npm文档:https://www.npmjs.com/package/echarts-for-react 由于npm上已经有针对react项目出的echarts插件,所以在这里直接安装 第一步: ...
- vue按需引入/全局引入echarts
npm install echarts -S 1.按需引入 新建echarts.js公共引入 // 文件路径 @/lib/echarts.js 自行配置 // 加载echarts,注意引入文件的路径 ...
随机推荐
- 201871010135 张玉晶 《面向对象程序设计(java)》 第一周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/wyt0455820/ ...
- win7 Adobe flash player 无法在线更新
1.win7 Adobe flash player 无法在线更新,提示应用程序初始化错误 解决方法: 1.https://www.flash.cn/看一下支持的版本,网上找对应版本离线包下载安装即可 ...
- 史上最全的各种C++ STL容器全解析
史上最全的C++ STL 容器大礼包 为什么\(C++\)比\(C\)更受人欢迎呢?除了\(C++\) 的编译令人感到更舒适,\(C++\)的标准模板库(\(STL\))也占了很重要的原因.当你还在用 ...
- angularjs ng-if妙用,ng-if解决父子组件异步传值
壹 ❀ 引 angularjs开发中,组件件相互通信传值是再普遍不过的操作了,比如我在父作用域中获取了一个数据,想要传递给子组件使用,做简单的做法就是通过scope传递,比如这样: <body ...
- python 实现自定义切片类
import numbers class Group: #支持切片操作 def __init__(self, group_name, company_name, staffs): self.group ...
- Visual Studio 基础设置
重置开发环境 菜单栏中选择“工具”/“导入和导出设置”/“重置所有设置” 设置行号 菜单栏中选择“工具”/“选项”/“文本编辑器”/“行号” 全屏显示 菜单栏中选择“视图”/“全屏显示” 为程序设置版 ...
- mybatis关联关系映射
1.一对多关联关系 2.多对多关联关系 首先先用逆向生成工具生成t_hibernate_order.t_hibernate_order_item t_hibernate_book.t_hibernat ...
- PlayJava Day005
今日所学: /* 2019.08.19开始学习,此为补档. */ 类:一类事物的抽象体(如全人类,学生类,订单类) 对象:具体的个体(如张三,某个外卖订单) 对象具有属性和行为. 声明的属性语句一般放 ...
- Linux网络——配置网络之ifconfig家族命令
Linux网络——配置网络之ifconfig家族命令 摘要:本文主要学习了ifconfig家族用来配置网络的命令. ifconfig命令 ifconfig命令用来显示或设置网络接口信息,设置只是临时生 ...
- Java生鲜电商平台-电商中海量搜索ElasticSearch架构设计实战与源码解析
Java生鲜电商平台-电商中海量搜索ElasticSearch架构设计实战与源码解析 生鲜电商搜索引擎的特点 众所周知,标准的搜索引擎主要分成三个大的部分,第一步是爬虫系统,第二步是数据分析,第三步才 ...