顺晟科技
2021-07-09 10:32:32
358
Angular8 引入百度Echarts,进行图表分析
原文地址:传送门
npm install echarts -S
npm install ngx-echarts -S
npm install @types/echarts -D
{
"scripts": [
"../node_modules/echarts/dist/echarts.min.js" // or echarts.js for debug purpose
],
}
这里有个坑,记得在你调用了echarts的相关模块的Module里面引入NgxEchartsModule,不然会报错:Template parse errors: Can't bind to 'options' since it isn't a known property of 'div'.所以切记
import { NgxEchartsModule } from 'ngx-echarts';
@NgModule({
imports: [
...,
NgxEchartsModule
],
...
})
export class AppModule { }
<div echarts [options]="chartOption"></div>
scss
.demo-chart {
height: 400px;
}
component
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'
}]
}
23
2022-09
23
2022-09
23
2022-09
23
2022-09
13
2022-09
13
2022-09