| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <template>
- <div :class="className" id="echart-customer1" :style="{height:height,width:width}" />
- </template>
- <script>
- import echarts from 'echarts'
- require('echarts/theme/macarons') // echarts theme
- import { debounce } from '@/utils'
- import { getStoreOrderData } from "@/api/index";
- const animationDuration = 6000
- export default {
- props: {
- className: {
- type: String,
- default: 'chart1'
- },
- width: {
- type: String,
- default: '100%'
- },
- height: {
- type: String,
- default: '300px'
- }
- },
- data() {
- return {
- chart: null,
- dates:[],
- orderCount:[],
- payPrice:[]
- }
- },
- mounted() {
- this.getStoreOrderData()
- this.__resizeHandler = debounce(() => {
- if (this.chart) {
- this.chart.resize()
- }
- }, 100)
- window.addEventListener('resize', this.__resizeHandler)
- },
- beforeDestroy() {
- if (!this.chart) {
- return
- }
- window.removeEventListener('resize', this.__resizeHandler)
- this.chart.dispose()
- this.chart = null
- },
- methods: {
- getStoreOrderData(){
- var that=this;
- getStoreOrderData().then((response) => {
- this.dates=response.dates;
- this.orderCount=response.orderCount;
- this.payPrice=response.payPrice;
- setTimeout(() => {
- that.initEchart();
- }, 500);
- });
- },
- initEchart(){
- var option = {
- tooltip: {
- trigger: 'axis',
- axisPointer: { // 坐标轴指示器,坐标轴触发有效
- type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
- }
- },
- legend: {
- data: ['订单数', '订单金额']
- },
- grid: {
- left: '3%',
- right: '4%',
- bottom: '3%',
- containLabel: true
- },
- xAxis: [
- {
- type: 'category',
- data: this.dates
- }
- ],
- yAxis: [
- {
- type: 'value',
- axisLabel:{
- formatter:'{value}'
- }
- }
- ],
- series: [
- {
-
- name: '订单数',
- type: 'line',
- emphasis: {
- focus: 'series'
- },
- data: this.orderCount
- },
- {
-
- name: '订单金额',
- type: 'line',
- emphasis: {
- focus: 'series'
- },
- data: this.payPrice
- }
- ]
- };
- this.chart=echarts.init(document.getElementById("echart-customer1"));
- this.chart.setOption(option,true);
- },
- }
-
-
- }
- </script>
|