导入Echarts:
import echarts from 'echarts';
<div class="table1" id="table1"></div>
- 3、初始化eCharts实例对象:在方法类中声明一个方法drawChart(),将初始化代码以及相关配置存入方法中
var myChart = this.$echarts.init(document.getElementById('table1'));
var option = {
title: {
text: 'DL Loading Rate'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
name: 'Email',
type: 'line',
stack: 'Total',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: 'Union Ads',
type: 'line',
stack: 'Total',
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: 'Video Ads',
type: 'line',
stack: 'Total',
data: [150, 232, 201, 154, 190, 330, 410]
},
{
name: 'Direct',
type: 'line',
stack: 'Total',
data: [320, 332, 301, 334, 390, 330, 320]
},
{
name: 'Search Engine',
type: 'line',
stack: 'Total',
data: [820, 932, 901, 934, 1290, 1330, 1320]
}
]
};
- 5、将配置项设置给echarts实例对象
使用刚指定的配置项和数据显示图表。//直接写在方法中
myChart.setOption(option);
mounted() {
this.drawChart();
},
使用心得
window.addEventListener('resize', () => {
myChart.resize()
})
axisLine:{
show:true
},
axisTick:{
show:true
},
offset: 50,
axisLabel: {
formatter: '{value} ml'
}
- 改变折线颜色、粗细:
在series里给每条折线加个itemStyle即可:
itemStyle: {
normal: {
color: '#a80000', //改变折线点的颜色
lineStyle: {
color: '#a80000' //改变折线颜色
width:3,
}
}
},
symbol:'circle',//节点为实心圆
symbolSize:10,
itemStyle: {
normal: {
label:{
show:true ,//在每个上面显示当前值
formatter: function (params) {
return params.value + '%';
}
},
}
}