<template>
  <div class="barbody">
    <v-chart ref="chart" :forceFit="true" :height="height" :data="dataSource" :scale="scale" :padding="padding">
      <v-tooltip />
      <v-axis />
      <v-interval position="x*y" :label="labelInterval" :opcaity="1"  :color="[['l(90) 0:#5491F8 1:#fff']]"></v-interval>
    </v-chart>
  </div>
</template>

<script>
import { triggerWindowResizeEvent } from '@/utils/util'

export default {
  name: 'ChartBar',
  props: {
    dataSource: {
      type: Array,
      required: true
    },
    yaxisText: {
      type: String,
      default: 'y'
    },
    title: {
      type: String,
      default: ''
    },
    height: {
      type: Number,
      default: 254
    }
  },
  data() {
    return {
      padding: ['15', 'auto', '40', '40'],
      labelInterval: [
        'y',
        {
          formatter: function formatter(text) {
            return text
          },
          offset: 10
        },
      ]
    }
  },
  computed: {
    scale() {
      return [
        {
          dataKey: 'y',
          alias: this.yaxisText
        }
      ]
    }
  },
  mounted() {
    triggerWindowResizeEvent()
  }
}
</script>
<style scoped>
.barbody {
  margin-top: 0px;
}
</style>
