Angular6+引入 Echarts4+ 并使用

1、安装 echarts (默认最新)

    npm install --save-dev echarts

2、安装ngx-echarts(默认最新)

    npm install ngx-echarts --save

3、Angular项目中引入 echarts

   在 angular.json中(具体文件路径根据node_modules引入的版本路径)

"projects": {
    "architect": {
        "build": {
            "options": {
                "scripts": [
                      "./node_modules/echarts/dist/echarts.min.js",
                      "./node_modules/echarts/map/js/china.js",
                      "./node_modules/echarts/dist/extension/bmap.js"
                 ],
             }
        }
    }

}

4、使用echarts

4.1  app.component.html

<div>
  <div echarts [options] = "chartOption" [loading]="showloadin
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Angular中实现Echarts的3D饼图,需要先安装Echarts库和它的类型定义: ``` npm install echarts --save npm install @types/echarts --save-dev ``` 然后在组件中引入echarts: ```typescript import * as echarts from 'echarts'; ``` 在模板中添加一个`div`元素作为Echarts的容器: ```html <div #chart style="width: 600px; height: 400px;"></div> ``` 在组件中获取这个`div`元素: ```typescript @ViewChild('chart', { static: true }) chartElement: ElementRef; ``` 然后在`ngOnInit`生命周期钩子函数中使用Echarts的API来绘制3D饼图: ```typescript ngOnInit() { const chart = echarts.init(this.chartElement.nativeElement); chart.setOption({ tooltip: { trigger: 'item', formatter: '{a} <br/>{b}: {c} ({d}%)' }, series: [ { name: '访问来源', type: 'pie', radius: ['50%', '70%'], avoidLabelOverlap: false, label: { show: false, position: 'center' }, emphasis: { label: { show: true, fontSize: '30', fontWeight: 'bold' } }, labelLine: { show: false }, data: [ { value: 335, name: '直接访问' }, { value: 310, name: '邮件营销' }, { value: 234, name: '联盟广告' }, { value: 135, name: '视频广告' }, { value: 1548, name: '搜索引擎' } ], itemStyle: { emphasis: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' }, normal: { color: function(params) { // build a color map as your need. const colorList = [ '#FF6666', '#FFCC66', '#99CC66', '#66CCCC', '#6699CC', '#CC99CC' ]; return colorList[params.dataIndex]; } } } } ] }); } ``` 这个例子中的3D饼图是一个有五个扇形的图,每个扇形的颜色、名称和数值都是自定义的。你可以根据自己的需求修改这个例子或者参考Echarts官方文档中的其他示例来自定义你自己的3D饼图。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值