记录生活中的点滴,分享、学习、创新
最近突发奇想,想自己做一个理财分析记录的网页,主要给自己记账,然后想到了把每天,每周的消费用图标分析出来,于是就需要用到百度的echarts图标插件,talk is cheep, show me the code。
1. npm 安装ngx-echarts及相关的依赖
1 2 3 | npm install echarts -Snpm install ngx-echarts -Snpm install @types/echarts -D |
2. 添加js引导文件
1 2 3 4 5 | { "scripts": [ "../node_modules/echarts/dist/echarts.min.js" // or echarts.js for debug purpose ],} |
3. AppModule引入NgxEchartsModule
这里有个坑,记得在你调用了echarts的相关模块的Module里面引入NgxEchartsModule,不然会报错:Template parse errors: Can't bind to 'options' since it isn't a known property of 'div'.所以切记
1 2 3 4 5 6 7 8 9 10 | import { NgxEchartsModule } from 'ngx-echarts'; @NgModule({ imports: [ ..., NgxEchartsModule ], ...})export class AppModule { } |
4. 使用echarts
html
1 | <div echarts [options]="chartOption" class="demo-chart"></div> |
scss
1 2 3 | .demo-chart { height: 400px;} |
component
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | import { EChartOption } from 'echarts';chartOption: EChartOption = { xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] }, yAxis: { type: 'value' }, series: [{ data: [820, 932, 901, 934, 1290, 1330, 1320], type: 'line' }]} |
5. 参考网站
https://www.npmjs.com/package/ngx-echartsangular echarts 在线模板