NPM 安装 ECharts
npm install echarts --save
引入 ECharts
import * as echarts from 'echarts';
var myChart = echarts.init(document.getElementById('main'));
myChart.setOption({
title: {
text: 'ECharts 入门示例'
},
tooltip: {},
xAxis: {
data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
});
按需引入 ECharts 图表和组件
/ 引入 echarts 核心模块,核心模块提供了 echarts 使用必须要的接口。
import * as echarts from 'echarts/core';
import {
BarChart
} from 'echarts/charts';
import {
TitleComponent,
TooltipComponent,
GridComponent
} from 'echarts/components';
import {
CanvasRenderer
} from 'echarts/renderers';
echarts.use(
[TitleComponent, TooltipComponent, GridComponent, BarChart, CanvasRenderer]
);
var myChart = echarts.init(document.getElementById('main'));
myChart.setOption({
...
});
option里的设置
var option = {
grid: {
left: 30,
right:'10%',
height: '50%',
bottom: 110
}
}
深色背景和浅色标签
setOption({
backgroundColor: '#2c343c'
})
setOption({
textStyle: {
color: 'rgba(255, 255, 255, 0.3)'
}
})