npm install echarts -S
npm install ngx-echarts -S
import { NgxEchartsModule } from 'ngx-echarts';
/**
* This will import all modules from echarts.
* If you only need custom modules,
* please refer to [Custom Build] section.
*/
import * as echarts from 'echarts';
@NgModule({
imports: [
NgxEchartsModule.forRoot({
echarts,
}),
],
})
export class AppModule {}
<div echarts [options]="chartOption" class="demo-chart">div>
要设置容器的高度
.demo-chart {
height: 400px;
}
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',
},
],
};
"scripts": [
"node_modules/echarts/dist/echarts.min.js"
]
<div id="chart-container" class="demo-chart">div>
要设置容器的高度
.demo-chart {
height: 400px;
}
// 画折线图
drawLineChartByData (eventObj: any) {
let chartOption = {
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',
}],
}
var myChart = echarts.init(document.getElementById('chart-container'));
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(chartOption)
}