Vuechart-js图表不会调整大小

时间:2019-07-10 16:24:10

标签: javascript vue.js chart.js vue-chartjs

我已经基于一些用户数据创建了一个甜甜圈图,并将其显示在摘要页面上。当按下按钮时,将显示甜甜圈图,但是该图太大,无法调整大小。

正如文档所说,我尝试将选项设置为{response:false,maintainAspectRatio:false}和{response:true,maintainAspectRatio:false},但是没有运气。图表大小保持不变,太大了。

这是我的DonutChart.js

import { Doughnut } from 'vue-chartjs';

export default {
  extends: Doughnut,
  props: ['data', 'options'],
  mounted() {
    // this.chartData is created in the mixin.
    // If you want to pass options please create a local options object
  },
  computed: {
    chartData() {
      return this.data;
    },
    chartOptions() {
      return this.options;
    },
  },
  methods: {
    renderLineChart() {
      this.renderChart({
        labels: ['Unconfirmed', 'Confirmed'],
        datasets: [
          {
            label: 'Data One',
            backgroundColor: ['#E46651', '#41B883', '#00D8FF'],
            data: this.chartData,
          },
        ],
      });
    },
  },
  watch: {
    chartData() {
      this.renderLineChart();
    },
  },
};

这是我的Summary.vue

<template>
<div>
 <button class="button" @click="generateReport">
    <span>{{enabled_users + total_users}}</span>
    <b-icon icon="account-multiple" size="is-small"></b-icon>
 </button>
 <div :width="100" :height="100" class="stats">
     <h1>Stats component</h1>
     <center><doughnut-chart  :width="100" :height="100" :data="dataChart" :options='optionsChart'>
     </doughnut-chart></center>
  </div>
  </div>
</template>

<script>
/* eslint no-param-reassign: 0 */
/* eslint arrow-body-style: 0 */
/* eslint arrow-parens: 0 */
import { mapState, mapGetters, mapActions } from 'vuex';
import DoughnutChart from './DonutChart';

export default {
  name: 'Summary',
  components: {
    DoughnutChart,
  },
  data() {
    return {
      dataChart: [0, 0],
      optionsChart: {
        responsive: false,
      },
      searchTerm: '',
      checkedRows: [],
      selectedGroup: null,
      defaultOpenedDetails: [],
      enabled_users: 0,
      total_users: 0,
    };
  },
  computed: {
    ...mapState('auth', ['allUsers', 'groups', 'loadingUsers', 'userAuthEvents']),
    ...mapGetters('auth', ['userGroups']),
    filteredUsers() {
      return this.allUsers.filter(user => {
        return user.Email.toLowerCase().indexOf(this.searchTerm.toLowerCase()) > -1;
      });
    },
    numberOfUsers() {
      return this.allUsers.length();
    },
  },
  methods: {
    ...mapActions({
      getAllUsers: 'auth/getAllUsers',
      getAllGroups: 'auth/getAllGroups',
      addUserToGroup: 'auth/addUserToGroup',
      deleteUsers: 'auth/deleteUsers',
      listGroupsForUser: 'auth/listGroupsForUser',
      listAuthEventsForUser: 'auth/listAuthEventsForUser',
    }),

    selectAllUsers() {
      this.allUsers.forEach(
        (user) => {
          if (user.Enabled === true) {
            this.enabled_users += 1;
          } else { this.total_users += 1; }
        },
        this.listAuthEventsForUser('test@test.com'),
        // console.log(this.userAuthEvents),
      );
    },

    updateChart() {
      this.dataChart = [this.total_users, this.enabled_users];
    },

    generateReport() {
      this.selectAllUsers();
      this.updateChart();
    },
  },
  mounted() {
    this.selectAllUsers();
  },
};

</script>
<style>
.b-table .table {
  background: transparent;
}
</style>

我希望图表可以调整为100px x 100px,但实际上是900x900或类似的大小。

0 个答案:

没有答案