您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

在Angular2.0/4.0中如何使用Echarts图表

2024/3/17 7:01:14发布33次查看
本篇文章主要介绍了angular2.0/4.0 使用echarts的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
前言:在开发中现在需要使用echarts来制作图标,所以就在网络上各种找资料,最后发现ngx-echarts轮子可用。那么就走一波.
方式: 使用echarts和ngx-eachrts两个依赖,借助于ngx..,是因为echarts是基于js编写,没有ts文件。所以就使用ngx-echarts来使用即可。
第一步:安装依赖
npm install echarts --savenpm install ngx-echarts --save
第二步:在module中引入
import { ngxechartsmodule } from 'ngx-echarts';@ngmodule({ imports: [ ...,// 引入module ngxechartsmodule ],})export class appmodule { }
第三步:在angular-cli中添加js引入
// edit .angular-cli.json{ "scripts": [ // add this: 注意,在echarts中可能没有提供echarts.min.js但是肯定有echarts.js的。对应引入即可。 "../node_modules/echarts/dist/echarts.min.js"// 还可以添加中英文,主题。。。。 ],}
第四步:页面中使用
<p echarts [options]="options" [loading]="isloading" class="demo-chart"></p>
各种文件
. html
<p echarts [options]="options" class="demo-chart"></p>
. ts
options: any; constructor() { } ngoninit() { let xaxisdata = []; let data1 = []; let data2 = []; for (let i = 0; i < 100; i++) { xaxisdata.push('category' + i); data1.push((math.sin(i / 5) * (i / 5 - 10) + i / 6) * 5); data2.push((math.cos(i / 5) * (i / 5 - 10) + i / 6) * 5); } this.options = { legend: { data: ['bar', 'bar2'], align: 'left' }, tooltip: {}, xaxis: { data: xaxisdata, silent: false, splitline: { show: false } }, yaxis: { }, series: [{ name: 'bar', type: 'bar', data: data1, animationdelay: function (idx) { return idx * 10; } }, { name: 'bar2', type: 'bar', data: data2, animationdelay: function (idx) { return idx * 10 + 100; } }], animationeasing: 'elasticout', animationdelayupdate: function (idx) { return idx * 5; } }; }
. appmodule 就不在叙述了
最终的结果:
最后
当然是附上ngx-echarts的官网咯,以上的例子其实就是官网例子而已。
在网络上看到有的也是使用该组件,但是是较老的版本了,所以就自己写一个正在使用的。
当然,需要事件,其他的就在官网查看即可。因为我也才正在使用,具体的问题都是需要具体的分析才行。所以其余的就不在赘述。
使用中遇到的问题?
我使用ng2-admin的后台框架,在该框架中ngxechartsmodule,不能再appmodule.ts中引入。具体原因不详,猜测是由于ng2-admin导致的。
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
在mac中如何安装nvm(详细教程)
在jquery中有关手机触屏滑动功能
使用dataset如何实现图片延时加载
在angular中如何实现双向数据绑定
以上就是在angular2.0/4.0中如何使用echarts图表的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product