18910140161

在有角的中使用展示

顺晟科技

2021-07-09 10:31:40

174

废话不多说,直接开始

安装echarts:npm install echarts --save在需要使用echarts的component中引入echarts:import * as echarts from 'echarts';

由于没有在展示echarts的dom中使用angular指令可以直接在生命周期函数ngOnInit中使用this.initCharts();

ngOnInit(): void {
  console.log('ngOnInit()');
  this.initCharts();
}

4.定义dom

<div></div>

5.定义initCharts()函数

initCharts(): void {
  const lineChart = echarts.init(document.querySelector('.lineChart'));
  const option = {
    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'
 }]
  };
  lineChart.setOption(option);
}

其结果为:
image.png

相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航