这是我的图表:
<script>
import { Bar, mixins } from 'vue-chartjs';
export default {
extends: Bar,
mixins: [mixins.reactiveProp],
props: ['options'],
mounted() {
this.renderChart(this.chartData, this.options);
},
};
</script>
这是我的组件,一个带有日期选择器和图表的页面:
<template>
...
<datepicker v-model="periodStart"
minimum-view="month"
format="MMMM yyyy"
placeholder="Choose date"
language="ru"/>
<span class="dash">—</span>
<datepicker v-model="periodEnd"
minimum-view="month"
format="MMMM yyyy"
placeholder="Choose date"
language="ru"/>
<test-chart :chart-data="setData" />
</template>
<script>
import moment from 'moment';
import { mapGetters, mapActions } from 'vuex';
import Datepicker from 'vuejs-datepicker';
import TestChart from '../charts/TestChart';
export default {
data() {
return {
periodStart: new Date(),
periodEnd: new Date(),
};
},
components: {
Datepicker,
TestChart,
},
computed: {
...mapGetters(['getReport', 'getChartLabels', 'getChartData']),
setData() {
return {
options: {
scales: {
yAxes: [{
stacked: true,
ticks: {
beginAtZero: true,
min: 0,
},
}],
xAxes: [{
stacked: true,
ticks: {
beginAtZero: true,
categoryPercentage: 0.5,
barPercentage: 1,
},
}],
},
responsive: true,
maintainAspectRatio: false,
},
labels: this.getChartLabels,
datasets: [
{
label: 'Количество активных резюме',
backgroundColor: '#f87979',
data: this.getChartData,
},
],
};
},
},
</script>
当我第一次打开带有图表的页面时,它会正确显示从 0 开始的 yAxes。但是当我使用日期选择器选择一个期间并将数据传递给图表时,它会显示从后面的最小数字开始的 yAxes结尾。有人可以建议如何避免这种情况吗?
使此图表具有响应性也存在问题。不知何故,它忽略responsive: true
了选项。