angular+echart入门记录

一、npm 安装 这三个

npm install echarts --save  //echarts的npm包
npm install ngx-echarts --save  //因为echarts 是js 的,所以需要这个来适配 ts
npm install @types/echarts -D //这个不知道什么作用,还没了解

二、app.moudule.ts 中操作

  1. import 引入
  2. @NgModule中 import
...
import { NgxEchartsModule } from 'ngx-echarts';
...

@NgModule({
	declarations: [
	  AppComponent,
	],
	imports: [
		...
		NgxEchartsModule.forRoot({
			echarts: () => import('echarts'), // or import('./path-to-my-custom-echarts')
			}),
		...
	],

})

三、 对应的 xxx.components.html 中

<div echarts   [options]="option_echart" class="demo-chart" ></div>

四、对应的 xxx.components.ts 中

export class WelcomeComponent implements OnInit {
	//echart 官网的入门示例
    option_echart = {
      title: {
          text: 'ECharts 入门示例'
      },
      tooltip: {},
      legend: {
          data:['销量']
      },
      xAxis: {
          data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
      },
      yAxis: {},
      series: [{
          name: '销量',
          type: 'bar',
          data: [5, 20, 36, 10, 10, 20]
      }]
  };
  constructor() { }
  ngOnInit() {
  }
}

五、 运行结果

在这里插入图片描述

说明:因为用到了ng-zorro,所以echart 在右侧显示

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值