<el-col :span="8">
<el-card shadow="always">
<line-chart :optionsReports="optionsReports" v-if="Object.keys(optionsReports).length"/>
</el-card>
</el-col>
<template>
<div class="line-chart">
<div id="main" ref="main"></div>
</div>
</template>
<script>
import * as echarts from "echarts";
export default {
name: "LineChart",
data(){
return {
options:{}
}
},
props: {
optionsReports: {
type: Object,
default: () => {
return {
title: {
text: "折线图",
},
tooltip: {},
xAxis: {
data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
axisLabel: {
interval: 0,
rotate: 15,
margin: 15,
},
},
yAxis: {},
series: [
{
name: "销量",
type: "line",
data: [5, 20, 36, 10, 10, 20],
},
],
};
},
},
},
mounted() {
var myChart = echarts.init(this.$refs.main);
this.options = JSON.parse( JSON.stringify(this.optionsReports) );
console.log(this.options);
this.options.title = {
text: "折线图"
}
this.options.grid = {
width: '80%',
left:'20%',
top:'30%'
}
this.options.legend.top = '10%'
this.options.tooltip = {
show:true,
position:'inside'
}
this.options.xAxis[0].axisLabel = {
interval: 0,
rotate: 15,
margin: 15,
}
this.options.xAxis[0].axisTick = {
alignWithLabel: true
}
this.options.yAxis[0].axisLine = {
show:true
}
this.options.series.forEach(r => {
delete r.areaStyle
r.smooth = true
});
myChart.setOption(this.options);
window.LineChart = myChart;
},
};
</script>
<style scoped lang="scss">
#main {
height: 300px;
}
</style>