我正在使用 PrimeNG 图表(基于 Chart.js)。 我知道要设置要显示的最大标签数。 文档显示了这一点: ticks.max String - 要显示的最大项目。必须是标签数组中的值
但我不知道该把它放在哪里,并且在互联网上找不到任何东西。 我的图表选项现在如下所示:
this.options = {
animation: false,
legend: {
display: true,
labels: {
boxWidth: 0,
}
},
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: "ms"
},
ticks: {
beginAtZero: true,
suggestedMax: 100,
}
}],
xAxes: [{
scaleLabel: {
display: true,
labelString: "sec"
},
ticks: {
beginAtZero: true,
}
}]
}
}
我尝试在选项中的不同位置添加ticks.max,但总是收到“意外标记”错误。 我可以在“刻度”内设置一个“最大值”,但这必须是一个数字,而不是我想要的。 而且,上面的文档还告诉我们,ticks.max 是来自 labels 数组的字符串。因此,ticks 对象中的“max”值肯定必须是其他值。
这可能是一个愚蠢的问题,但我找了很长时间,还是忍不住问。
最佳答案
根据文档,如果您想创建类别量表
,应该像这样工作:
.....
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: "ms"
},
ticks: {
beginAtZero: true,
suggestedMax: 100,
}
}],
xAxes: [{
scaleLabel: {
display: true,
labelString: "sec"
},
ticks: {
beginAtZero: true,
max: "a-value-from-array"
}
}]
}
我很想猜测您正在使用如下符号:
var y = { ticks.max: "hello" }
VM181:1 Uncaught SyntaxError: Unexpected token .
我认为这可以解释你的错误。
关于typescript - PrimeNG/Chart.js - 要显示的最大标签数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38507367/