我有一个包含大约 60 个 x 轴标签的数据集。我的折线图未显示 x 轴上的所有标签。
var ctx = this.refs.basicXYChart;
var config = {
type: 'line',
data: {
xLabels: Object.keys(result),
yLabels: Object.values(result),
datasets: [{
label: this.state.report.definition.name,
data: Object.values(result),
backgroundColor: 'rgba(154, 208, 245, 0.5)',
borderWidth: 1,
pointStyle: 'circle',
pointBackgroundColor: 'rgb(77, 172, 237)',
pointRadius: 5,
pointHoverRadius: 10,
borderWidth: 1,
borderColor: '#000000'
}]
},
options: {
scales: {
xAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: this.props.X_label
}
}],
yAxes: [{
position: 'left',
display: true,
scaleLabel: {
display: true,
labelString: this.props.Y_label
}
}]
}
}
};
if(y_type == 'category'){
config.options.scales.yAxes[0]['type'] = 'category';
}
var myChart = new Chart(ctx, config);
Run Code Online (Sandbox Code Playgroud)
我也想从0开始y轴
https://github.com/chartjs/Chart.js/issues/2801中解决了这个问题。
scales: {
xAxes: [{
ticks: {
autoSkip: false
}
}]
}
Run Code Online (Sandbox Code Playgroud)
可以在此处的文档中找到:http://www.chartjs.org/docs/latest/axes/cartesian/#tick-configuration
现在答案似乎有所不同:
options: {
scales: {
x: {
ticks: {
autoSkip: false
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8750 次 |
| 最近记录: |