【发布时间】:2019-05-11 14:59:35
【问题描述】:
ChartJS v2
我在 X 轴刻度标签与 X 轴标签重叠时遇到小屏幕问题(在 Chrome 中使用 iPhone 5 屏幕模拟器)。
我的Y轴标签也被剪掉了。
我尝试过为标签 2 使用 padding 和 lineHeight 无济于事。我还尝试将 X 轴刻度标签的最大/最小旋转值设置为 90 度,这使问题变得更糟。
上面截图中的例子使用了这些设置:
var ctx = document.getElementById("myChart").getContext("2d");
var chart = new Chart(ctx, {
// The type of chart we want to create
type: "bar",
// The data for our dataset
data: {
labels: [
"0k-40k",
"40k-80k",
"80k-100k",
"100k-120k",
"120k-160k",
"160k-180k",
"180k-220k"
],
datasets: [
{
label: "My First dataset",
backgroundColor: "rgb(255, 99, 132)",
borderColor: "rgb(255, 99, 132)",
data: [0, 10, 5, 2, 20, 30, 45]
}
]
},
// Configuration options go here
options: {
legend: {
display: false
},
scales: {
xAxes: [
{
ticks: {
autoSkip: false,
fontSize: 16,
fontStyle: "bold",
precision: 2,
suggestedMin: 0
},
scaleLabel: {
display: true,
fontSize: 16,
fontStyle: "bold",
labelString: "Chart Label X",
}
}
],
yAxes: [
{
ticks: {
fontSize: 16,
fontStyle: "bold",
precision: 2,
suggestedMin: 0
},
scaleLabel: {
display: true,
fontSize: 16,
fontStyle: "bold",
labelString: "Chart Label Y",
}
}
]
}
}
});
这看起来可能是 ChartJS 在旋转时没有正确计算标签高度的错误。其他人有这个问题吗?有解决办法吗?
【问题讨论】:
标签: javascript chart.js