<template>
  <div class="border">
    <label>Bar</label>
    <div id="bar" style="width:100%; height:400px"></div>
  </div>
</template>

<script>

import Echarts from 'echarts';

export default {
  props:{
    dataX : Array,
    dataY: Array,
    series: Array
  },
  data(){
    return {
    }
  },
  computed:{
  },
  mounted(){
   this.mountChartBar();
  },
  watch: {
    dataX(){
      this.mountChartBar();
    }
  },
  methods:{
    mountChartBar(){
      let myChart = Echarts.init(document.getElementById('bar'));
      myChart.setOption(this.setOptions());
    },
    setOptions(){
      let option = {
        title: {
          text: 'Echarts entry example'
        },
        tooltip: {},
        legend: {
          data: ['Sales']
        },
        toolbox: {
          show : true,
          feature : {
              dataView : {show: true, readOnly: false},
              magicType : {show: true, type: ['line', 'bar']},
              restore : {show: true},
              saveAsImage : {show: true},
              dataZoom: { show: true, title: {
                  zoom: 'zoom',
                  back: 'back'
              }}
          }
      },
        xAxis: {
          data: this.dataX
        },
        yAxis: {},
        series: [{
          name: 'Sales',
          type: 'bar',
          data: this.series
        }]
      };
      return option;
    }
  },
  created(){
  }
}
</script>

<style>
a.link-tag { color: inherit; } 
</style>
