mkl_power_box/components/trend-chart-line.js

174 lines
5.3 KiB
JavaScript

/**
* 顶部header
*/
Vue.component("trend-chart-line", {
template: `
<div :style="{'height': height+'px'}" ref="chart">
</div>
`,
props: {
data:{
type:Object
},
height:{
type:Number
},
},
data() {
return {
classData:[],
}
},
mounted(){
this.init()
},
methods: {
init(){
this.getChartData()
},
getChartData(){
//品类金额占比 饼图
var chChartPie = echarts.init(this.$refs.chart);
this.echartPie(chChartPie,this.data)
},
echartPie(chChart,data){
let newPromise = new Promise((resolve) => {
resolve()
})
//然后异步执行echarts的初始化函数
newPromise.then(() => {
var series = []
console.log(data)
for (let i = 0; i < data.lineData.length; i++) {
series.push({
name: data.legend[i],
type: "line",
smooth: true,
symbol: "circle",
symbolSize: 5,
showSymbol: false,
lineStyle: {
normal: {
width: 2,
},
},
itemStyle: {
normal: {
color: data.color[i],
borderWidth: 5,
},
},
data: data.lineData[i],
},)
}
var unit = ''
if(data.unit){
unit = '单位:'+data.unit
}
this.option = {
tooltip: {
trigger: "axis",
axisPointer: {
lineStyle: {
color: "#57617B",
},
},
},
legend: {
icon: "rect",
itemWidth: 14,
itemHeight: 10,
itemGap: 15,
data: data.legend,
top: -5,
textStyle: {
fontSize: 14,
color: "#c8dbfc",
},
},
grid: {
top:'15%',
left: "3%",
right: "3%",
bottom: "2%",
containLabel: true,
},
xAxis: {
boundaryGap: false,
type: "category",
data: data.date,
axisLine: {
//坐标轴轴线相关设置。数学上的x轴
show: true,
lineStyle: {
color: "#25597e",
type: "dashed",
},
},
axisTick: {
show: false
},
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
color: "#c5d9fc",
margin: 20,
fontSize:14
},
},
},
yAxis: {
name: unit,
type: "value",
axisLine: {
//坐标轴轴线相关设置。数学上的x轴
show: false,
lineStyle: {
color: "#c5d9fc",
type: "dashed",
},
},
axisTick: {
show: false
},
axisLabel: {
show: true,
//坐标轴刻度标签的相关设置
textStyle: {
color: "#c5d9fc",
margin: 20,
fontSize:14
},
},
splitLine: {
show: true,
lineStyle: {
color: "#25597e",
type: "dashed",
},
},
},
series: series,
};
chChart.setOption(this.option,true);
window.onresize = chChart.resize;
})
},
},
watch:{
data: function (n,o) {
this.getChartData()
}
}
})