vue 之折线图 +tab栏目切换
<template>
<div class="line_chart">
<div class="chart" ref="line_chart"></div>
</div>
</template>
<script>
export default {
name: "LineChart",
components: {},
props: {
lineChartData: {
type: Object,
default() {
return {};
},
},
},
data() {
return {};
},
mounted() {
this.getLineChart(this.lineChartData);
},
watch: {
lineChartData(newValue) {
this.getLineChart(newValue);
},
},
methods: {
getLineChart(lineChartData) {
let lineChart = this.$echarts.init(this.$refs.line_chart);
let option = {
xAxis: {
type: "category",
data: lineChartData.weeklyX,
axisTick: {
show: false,
},
axisLine: {
lineStyle: {
color: "#ccc",
width: 1,
},
},
axisLabel: {
textStyle: {
fontSize: 10,
color: "#666",
},
},
},
yAxis: {
type: "value",
max: 2000,
min: 0,
minInterval: 0,
interval: 500,
axisLabel: {
textStyle: {
fontSize: 10,
color: "#666",
},
},
axisTick: {
show: false,
},
axisLine: {
show: false,
},
splitLine: {
lineStyle: {
color: "#f8f8f8",
},
},
},
grid: {
left: "0",
top: "10",
right: "0",
bottom: "0",
containLabel: true,
},
series: [
{
data: lineChartData.weeklyData,
type: "line",
symbolSize: 10,
itemStyle: {
borderColor: "#3987ed",
borderWidth: 3,
color: "#333",
},
lineStyle: {
color: "#3887ed",
},
emphasis: {
color: "#3987ed",
borderColor: "#3987ed",
},
label: {
normal: {
show: true,
position: [-15, -18],
fontSize: 10,
},
},
areaStyle: {
color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: "#1568F6",
},
{
offset: 1,
color: "rgba(4,182,243,0.00) ",
},
]),
},
},
],
};
lineChart.setOption(option);
window.addEventListener("resize", function () {
lineChart.resize();
});
},
},
};
</script>
<style lang="scss" scoped>
.line_chart {
width: 345px;
height: 198px;
background: #eee;
.chart {
width: 100%;
height: 100%;
}
}
</style>