123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <template>
- <div :class="className" id="echart-customer2" style="width: 100%; height: 260px;" />
- </template>
- <script>
- import echarts from 'echarts'
- require('echarts/theme/macarons') // echarts theme
- import { debounce } from '@/utils'
- import { getStorePaymentData } from "@/api/index";
- const animationDuration = 6000
- export default {
- props: {
- className: {
- type: String,
- default: 'chart2'
- },
- width: {
- type: String,
- default: '100%'
- },
- height: {
- type: String,
- default: '260px'
- }
- },
- data() {
- return {
- chart: null,
- dates:[],
- orderCount:[],
- payMoney:[]
- }
- },
- mounted() {
- this.getStorePaymentData()
- 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: {
- getStorePaymentData(){
- var that=this;
- getStorePaymentData().then((response) => {
- this.dates=response.dates;
- this.orderCount=response.orderCount;
- this.payMoney=response.payMoney;
- setTimeout(() => {
- that.initEchart();
- }, 500);
- });
- },
- initEchart(){
- var option = {
- series: [{
- type: 'gauge',
- axisLine: {
- lineStyle: {
- width: 10,
- color: [
- [0.2, '#1c4587'],
- [0.8, '#980000'],
- [1, '#009100']
- ]
- }
- },
- pointer: {
- itemStyle: {
- color: 'auto'
- }
- },
- axisTick: {
- distance: -30,
- length: 8,
- lineStyle: {
- color: '#fff',
- width: 2
- }
- },
- splitLine: {
- distance: -30,
- length: 30,
- lineStyle: {
- color: '#fff',
- width: 4
- }
- },
- axisLabel: {
- color: 'auto',
- distance: 0,
- fontSize: 14
- },
- detail: {
- fontSize: 18,
- valueAnimation: true,
- formatter: '{value} %',
- color: 'auto'
- },
- data: [{
- value: 1
- }]
- }]
- };
- this.chart=echarts.init(document.getElementById("echart-customer2"));
- this.chart.setOption(option,true);
- },
- }
- }
- </script>
|