生产分析
This commit is contained in:
93
src/views/core/analysis/LineChart.vue
Normal file
93
src/views/core/analysis/LineChart.vue
Normal file
@@ -0,0 +1,93 @@
|
||||
<!--
|
||||
* @Author: zhp
|
||||
* @Date: 2023-09-13 09:02:25
|
||||
* @LastEditTime: 2023-09-13 10:33:20
|
||||
* @LastEditors: zhp
|
||||
* @Description:
|
||||
-->
|
||||
<template>
|
||||
<div :class="className" :style="{height:height,width:width}" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import * as echarts from 'echarts'
|
||||
require('echarts/theme/macarons') // echarts theme
|
||||
// import resize from './mixins/resize'
|
||||
|
||||
export default {
|
||||
// mixins: [resize],
|
||||
props: {
|
||||
className: {
|
||||
type: String,
|
||||
default: 'chart'
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: '100%'
|
||||
},
|
||||
height: {
|
||||
type: String,
|
||||
default: '350px'
|
||||
},
|
||||
// autoResize: {
|
||||
// type: Boolean,
|
||||
// default: true
|
||||
// }
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
chart: null
|
||||
}
|
||||
},
|
||||
// watch: {
|
||||
// chartData: {
|
||||
// deep: true,
|
||||
// handler(val) {
|
||||
// this.setOptions(val)
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
mounted() {
|
||||
// this.$nextTick(() => {
|
||||
// this.initChart()
|
||||
// })
|
||||
},
|
||||
// beforeDestroy() {
|
||||
// if (!this.chart) {
|
||||
// return
|
||||
// }
|
||||
// this.chart.dispose()
|
||||
// this.chart = null
|
||||
// },
|
||||
methods: {
|
||||
initChart(xData, yData,lineName) {
|
||||
console.log(xData,yData);
|
||||
this.chart = echarts.init(this.$el, 'macarons')
|
||||
this.setOptions(xData, yData, lineName)
|
||||
},
|
||||
setOptions(xData, yData, lineName) {
|
||||
let seriesData = []
|
||||
lineName.forEach((item,index) => {
|
||||
seriesData.push({
|
||||
name: item,
|
||||
data: yData[index],
|
||||
type: 'line',
|
||||
})
|
||||
})
|
||||
this.chart.setOption({
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: xData
|
||||
},
|
||||
legend: {
|
||||
data:lineName
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value'
|
||||
},
|
||||
series: seriesData
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user