因为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;
}

最新文章

  1. PS通过滤色实现简单的图片拼合
  2. MongoDB学习笔记七:管理
  3. SQL中的charindex函数与reverse函数用法
  4. sqlldr使用
  5. Android EditText自动弹出输入法焦点
  6. C51与汇编混合编程详解
  7. UDP数据接收服务器
  8. DotNetBar.Bar控制Y顺序控制方向
  9. LeetCode 108: Convert Sorted Array to Binary Search Tree DFS求解
  10. typeahead + JDK 8 并行流 + redis 高速即时查询.
  11. 如何正确的理解和解决 ORA-01843:not a valid month
  12. HTTP/1.0 vs HTTP/1.1 vs HTTP/2
  13. Nginx 和 IIS 实现动静分离(转)
  14. 使用nginx实现一个主机部署多域名指向不同docker项目
  15. [转]GitHub上优秀的Go开源项目
  16. Opencv——相机标定
  17. PHP之mb_convert_variables使用
  18. 关于Unity的C#基础学习(五)
  19. 设置 Quick-Cocos2d-x 在 Windows 下的编译环境
  20. 微信小程序自动去除input空格的方法

热门文章

  1. windows搭建成代理服务器 CCProxy
  2. LeetCode 5129. 下降路径最小和 II Minimum Falling Path Sum II
  3. 超实用的Java web面试题
  4. 第05组 Alpha冲刺(4/4)
  5. AJAX 实现form表单提交
  6. DirectShow 常用函数总结
  7. python基础(26):类的成员(字段、方法、属性)
  8. 深入理解JVM,类加载器
  9. 读取树莓派4B处理器(CPU)的实时温度
  10. JVM垃圾回收器原理及使用介绍