CHART.js 散点图中 x 轴的非数值
Non numeric for x-axis in scatter chart in CHART.js
我正在尝试使用 chartjs 生成散点图。在我的散点图中,我希望 x 轴刻度标签是一个字符串。但是如果我尝试下面的代码,我会在我的 x 轴标签 scale
中得到数字
datasets: [{
label: 'Scatter Dataset',
data: [{
x: "a",
y: 0
}, {
x: "b",
y: 3
}, {
x: "",
y: 5
}]
}]
如何将我的 x 轴刻度设置为字符串值并使图表正常工作?
我不相信你所要求的可以用散点图实现。 Documentation says it only accepts data in a point format. Hence your data definition is even incorrect. You can use line chart and give data in an array format (only y-axis values) and provide labels
property as array of strings you wish to display as x-axis labels. See the starting example 用于说明。
这是可以实现的,它在文档中。作为轴定义的一部分:
let chart = new Chart(ctx, {
类型: ...
数据: ...
选项: {
秤:{
x轴:[{
类型:'category',
标签:['January'、'February'、'March'、'April'、'May'、'June']
}]
}
}
});
于:https://www.chartjs.org/docs/latest/axes/cartesian/category.html
我正在尝试使用 chartjs 生成散点图。在我的散点图中,我希望 x 轴刻度标签是一个字符串。但是如果我尝试下面的代码,我会在我的 x 轴标签 scale
中得到数字datasets: [{
label: 'Scatter Dataset',
data: [{
x: "a",
y: 0
}, {
x: "b",
y: 3
}, {
x: "",
y: 5
}]
}]
如何将我的 x 轴刻度设置为字符串值并使图表正常工作?
我不相信你所要求的可以用散点图实现。 Documentation says it only accepts data in a point format. Hence your data definition is even incorrect. You can use line chart and give data in an array format (only y-axis values) and provide labels
property as array of strings you wish to display as x-axis labels. See the starting example 用于说明。
这是可以实现的,它在文档中。作为轴定义的一部分:
let chart = new Chart(ctx, { 类型: ... 数据: ... 选项: { 秤:{ x轴:[{ 类型:'category', 标签:['January'、'February'、'March'、'April'、'May'、'June'] }] } } });
于:https://www.chartjs.org/docs/latest/axes/cartesian/category.html