Advertisement

vue-echarts数据统计图表展示

阅读量:
复制代码
    <template>
    	<div>
    		<h1>统计</h1>
    		<div id="myChart" :style="{width:'100vw',height:'300px'}"></div>
    	</div>
    </template>
    
    <script>
    	let echarts = require('echarts/lib/echarts')
    	require('echarts/lib/chart/bar')
    	require('echarts/lib/chart/line')
    	require('echarts/lib/component/tooltip')
    	require('echarts/lib/component/toolbox');
    	require('echarts/lib/component/legend');
    	require('echarts/lib/component/markPoint');
    	require('echarts/lib/component/markLine');
    	require('echarts/lib/component/title')
    	import datajson from '../../demo.js'
    	export default {
    		name: 'demo',
    		data() {
    			return {
    				xdata: [],
    				ydata: []
    			}
    		},
    		mounted() {
    			for (var i = datajson.list.length - 1; i > 0; i--) {
    				this.xdata.push(datajson.list[i]['date'])
    				this.ydata.push(datajson.list[i]['num'])
    			}
    			this.drwaLine()
    		},
    		methods: {
    			drwaLine() {
    				let myChart = echarts.init(document.getElementById('myChart'))
    				myChart.setOption({
    					title: {
    						text: ''
    					},
    					tooltip: {
    						trigger: 'axis'
    					},
    					xAxis: {
    						data: this.xdata
    					},
    					yAxis: {
    						type: 'value'
    					},
    					series: [{
    						data: this.ydata,
    						type: 'line',
    						markPoint: {
    							data: [{
    									type: 'max',
    									name: '最大值'
    								},
    								{
    									type: 'min',
    									name: '最小值'
    								}
    							]
    						},
    						markLine: {
    							data: [{
    								type: 'average',
    								name: '平均值'
    							}]
    						}
    					}]
    				})
    			}
    		}
    	}
    </script>
    
    <style>
    	body{
    		margin: 0;
    	}
    </style>
    
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    代码解读
在这里插入图片描述

全部评论 (0)

还没有任何评论哟~