123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <!--
- * @Author: your name
- * @Date: 2021-10-12 09:10:42
- * @LastEditTime: 2021-12-21 13:29:30
- * @LastEditors: Please set LastEditors
- * @Description: 成本分析的柱状图
- * @FilePath: \hyyfClient\src\views\PdcData\analysis\CostHistogram.vue
- -->
- <template>
- <div class="cost-histogram">
- <div id="costHistogram"></div>
- </div>
- </template>
- <script>
- import { mapState } from "vuex";
- export default {
- props: {
- timeList: {
- type: Array,
- default: () => [],
- },
- dataList: {
- type: Array,
- default: () => [],
- },
- },
- computed: {
- ...mapState(["color"]),
- },
- data() {
- return {
- myChart: null,
- };
- },
- methods: {
- init() {
- let options = {
- color: [this.color],
- tooltip: {
- trigger: "axis",
- axisPointer: {
- type: "none",
- },
- },
- grid: {
- left: "3%",
- right: "12%",
- bottom: "6%",
- containLabel: true,
- },
- xAxis: {
- name: "时间",
- type: "category",
- data: this.timeList,
- axisTick: {
- show: false,
- },
- splitLine: {
- show: false,
- },
- // axisPointer: {
- // show: false,
- // },
- // axisTick: {
- // alignWithLabel: true,
- // },
- },
- yAxis: {
- name: "人次",
- type: "value",
- axisTick: {
- show: false,
- },
- splitLine: {
- show: false,
- },
- },
- series: [
- {
- name: "人次",
- type: "bar",
- barWidth: "15%",
- data: this.dataList,
- label: {
- show: true,
- verticalAlign: "bottom",
- },
- },
- ],
- };
- this.myChart.setOption(options, false);
- },
- },
- mounted() {
- this.myChart = this.$echarts.init(document.getElementById("costHistogram"));
- this.init();
- },
- watch: {
- color(newVal) {
- if (newVal) {
- this.myChart.clear();
- this.init();
- }
- },
- dataList: {
- handler() {
- this.myChart.clear();
- this.init();
- },
- },
- timeList: {
- handler() {
- this.myChart.clear();
- this.init();
- },
- },
- },
- };
- </script>
- <style scoped>
- .cost-histogram {
- display: inline-block;
- flex: 1;
- height: 100%;
- }
- #costHistogram {
- width: 100%;
- height: 100%;
- }
- </style>
|