123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <template>
- <div :id="'chart-lines' + id" style="width: 100%; height: 100%" />
- </template>
- <script>
- let myChart = null
- import echarts from 'echarts'
- export default {
- name: 'ChartLines',
- props: {
- id: {
- type: Number,
- default: 0
- },
- list: {
- type: Array,
- default: () => []
- }
- },
- watch: {
- list: {
- handler() {
- myChart.clear()
- this.init()
- },
- deep: true
- }
- },
- mounted() {
- this.init()
- },
- methods: {
- init() {
- myChart = echarts.init(document.getElementById('chart-lines' + this.id))
- const time = []
- const data = []
- if (this.list.length > 0) {
- this.list.forEach(item => {
- time.push(item.time)
- data.push(item.total / 100)
- })
- }
- const options = {
- tooltip: {
- trigger: 'axis'
- },
- color: ['#6BBEAE', '#1890FF'],
- xAxis: {
- type: 'category',
- boundaryGap: true,
- data: time,
- axisLine: {
- show: true,
- lineStyle: {
- color: '#aaa'
- }
- },
- axisLabel: {
- color: '#aaa'
- }
- },
- yAxis: [
- {
- type: 'value',
- name: '单位:元',
- boundaryGap: [0, '100%'],
- axisLine: { // y轴
- show: false
- },
- axisTick: {
- show: false
- },
- splitLine: {
- show: false
- }
- }
- ],
- series: [
- {
- name: `总收入`,
- type: 'line',
- // stack: 'Total',
- data: data,
- barWidth: 20,
- tooltip: {
- valueFormatter: function(value) {
- return value + ' 元'
- }
- }
- }
- ]
- }
- myChart.setOption(options)
- }
- }
- }
- </script>
- <style scoped>
- </style>
|