<template>
  <chart :options="bar()" class="bar" />
</template>

<script>
import { graphic } from "echarts/lib/export";
export default {
  props: {
    data: {
      type: Object,
      default: () => {
        return {
          data: 40,
          text: "模拟数据1.0"
        };
      }
    },
    bar_width: {
      type: String,
      default: "16px"
    },
    colors: {
      type: Array,
      default: () => {
        return ["#274fee", "#274fee"];
      }
    },
    bar_border_radius: {
      type: Array,
      default: () => {
        return [10, 10, 10, 10];
      }
    },
    show_split: {
      typr: Boolean,
      default: false
    }
  },
  data: () => ({
    navList: []
  }),
  mounted() {},
  methods: {
    bar() {
      let self = this;
      return {
        xAxis: [
          {
            type: "category",
            data: ["2019Q1", "2019Q2", "2019Q3", "2019Q4"],
            axisLabel: {
              margin: 20,
              color: "#0d1847",
              textStyle: {
                fontSize: 12
              }
            },
            axisLine: {
              lineStyle: {
                color: "#f2f2f2"
              }
            },
            axisTick: {
              show: false
            },
            splitArea: {
              show: self.show_split,
              interval: 0,
              areaStyle: {
                color: ["#f4f5fd", "#fff"],
                opacity: 0.5
              }
            }
          }
        ],
        yAxis: [
          {
            axisLabel: {
              color: "#a9aec0",
              textStyle: {
                fontSize: 12
              }
            },
            axisLine: {
              lineStyle: {
                color: "rgba(0, 0, 0, 0)"
              }
            },
            axisTick: {
              show: false
            },
            splitLine: {
              lineStyle: {
                color: "#f2f2f2",
                type: "solid"
              }
            }
          }
        ],
        series: [
          {
            type: "bar",
            data: [40, 80, 20, 16],
            barWidth: self.bar_width,
            itemStyle: {
              normal: {
                color: function(params) {
                  return new graphic.LinearGradient(
                    0,
                    0,
                    0,
                    1,
                    [
                      {
                        offset: 0,
                        color: self.colors[0] // 0% 处的颜色
                      },
                      {
                        offset: 1,
                        color: self.colors[1] // 100% 处的颜色
                      }
                    ],
                    false
                  );
                },
                barBorderRadius: self.bar_border_radius
              }
            }
          }
        ]
      };
    }
  }
};
</script>
<style scoped>
.bar {
  width: 100%;
  height: 100%;
}
</style>