vue.js - 调整 vue-chartjs 高度,同时保持响应
问题描述
需要图表 js 的帮助
实际上,我正在使用 VUE-CHARTJS 但它只是一个包装器
在左侧的折线图中,数字增加了 5(0、5、10、15 等)我希望它增加 10 并降低图表的高度,因此纵横比类似于 16/ 9
也可以让左边的数字说 5k+, 10k+, 15k+ 而不仅仅是 5, 10, 15
这是我的图表代码
<script>
import { Line } from 'vue-chartjs'
export default {
extends: Line,
data: () => ({
chartdata: {
labels: ['January', 'February', 'March', 'April', 'May','Jun'],
datasets: [
{
data: [12, 20, 27, 22, 14, 10],
borderColor: "#135193",
pointBackgroundColor: "#135193",
pointBorderColor: "#135193",
backgroundColor: 'rgba(255, 255, 255, 0)'
},
{
data: [3, 12, 17, 20, 30, 40],
borderColor: "#FF8811",
pointBackgroundColor: "#FF8811",
pointBorderColor: "#FF8811",
backgroundColor: 'rgba(255, 255, 255, 0)'
}
]
},
options: {
responsive: true,
legend: {
display: false
}
}
}),
mounted () {
this.renderChart(this.chartdata, this.options)
}
}
</script>
解决方案
是的,您可以使用 CSS 设置画布的尺寸并在选项中设置maintainAspectRatio
为false
,对于刻度,您可以使用刻度回调:
const labels = ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"];
const options = {
type: 'line',
data: {
labels,
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderColor: 'red',
backgroundColor: 'pink'
}]
},
options: {
maintainAspectRatio: false,
scales: {
yAxes: [{
ticks: {
callback: (val) => (`${val}K`)
}
}]
}
}
}
const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
canvas {
max-height: 180px;
max-width: 320px;
}
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
</body>
推荐阅读
- scheme - 评估复合程序元循环“应用”的顺序
- apache-nifi - 在“ExtractText”调用的 Nifi 处理器“InvokeHttp”中,您在哪里编写 POST 请求的正文
- android - 调试 espresso 测试在“实例化测试...”处挂起并出现 Object.wait 错误
- python - Python (cpython) 在内存屏障和原子性等方面的行为是否得到保证?
- vue.js - 在 Vue 中观察数组的添加/删除
- reactjs - UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server
- sqlite - 如何在主页中使用提供程序实例化 Moor_Flutter 数据库(daos)?
- java - 如何安装hadoop纱线?
- r - R tidy 按组添加摘要
- sql - 为表中的元组选择最大值