博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
angular2 echarts 插件ngx-echarts
阅读量:7071 次
发布时间:2019-06-28

本文共 2689 字,大约阅读时间需要 8 分钟。

图片描述

angular2使用百度统计图echarts插件

1、安装插件,必须安装echarts.js基础js文件和ngx-echarts插件文件

npm install echarts --savenpm install ngx-echarts --save

2、配置 echarts.js

首先要引入echarts.js文件A: 使用angular-cli创建项目,打开angular-cli.json,作如下配置{  "scripts": [    "../node_modules/echarts/dist/echarts.min.js"   ],}B: 使用webpack创建项目,打开webpack.common.js 作如下配置new webpack.ProvidePlugin({  echarts: "echarts"})C: 如果不知道使用什么创建项目,呵呵,可以直接在index.html文件中通过cdn链接引入echarts.js文件

3、配置ngx-echarts

import { AngularEchartsModule } from 'ngx-echarts';// 最新升级后,修改引入名称import {NgxEchartsModule} from 'ngx-echarts';...@NgModule({  imports: [    AngularEchartsModule  ],  ...})

4、html文件,其中包括配置和样式

5、在组件中书写配置,可以在echarts官网查询配置细节

import { Component, OnInit } from "@angular/core";@Component({  selector: "echarts",  templateUrl: "./echarts.component.html"})export class EchartsComponent implements OnInit {  public echartOption: any;  constructor() {  }  ngOnInit() {    this.echartOption = {      backgroundColor: '#2c343c',      title: {        text: 'Customized Pie',        left: 'center',        top: 20,        textStyle: {          color: '#ccc'        }      },      tooltip: {        trigger: 'item',        formatter: "{a} 
{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.3)' } } }, 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; } } ] } }}

6、通过标签<echarts></echarts>将这个组件引用到其他界面就可以使用了

注意:    1. 必须设置高度    2. 不要忘记引入echarts.js文件

7、如果想使用地图,那么先要在echarts网站下载地图的js文件,然后和配置echarts.js文件一样,做相应的配置,然后修改组件中的配置就可以了。

图片描述

转载地址:http://uekml.baihongyu.com/

你可能感兴趣的文章
Android开发之旅:组件生命周期(二)
查看>>
使用LVS+NAT搭建集群实现负载均衡
查看>>
LVM 磁盘分区扩容
查看>>
mysql5.6之key_buffer_size优化设置
查看>>
查看Linux服务器网卡流量小脚本shell和Python各一例
查看>>
Linux TC的ifb原理以及ingress流控
查看>>
AgileEAS.NET之敏捷并行开发方法
查看>>
Java源码分析系列之ArrayList读后感
查看>>
性能测试之手机号码python生成方式
查看>>
统计数据库大小的方法
查看>>
PHP递归遍历文件夹
查看>>
用户系列之五:用户SID查看之终结版
查看>>
ubuntu 11.10下载和编译Android源码
查看>>
千兆级LTE的一小步,5G之路的一大步
查看>>
跟我一起写 Makefile(一)
查看>>
管理日志-原创理论工具--技能方格图
查看>>
MPLS TE第一步:创建基本TE隧道
查看>>
windows中禁止U盘写入
查看>>
Bash技巧总结
查看>>
在窗体中添加标签Label、Icon图标
查看>>