我使用Chart.js(http://www.chartjs.org/),它的工作正常,但我有太大的X标签也与45度方向(是自动调整)。我想减少该文本的大小,是否可以只为X轴做?谢谢
gorkyyrv1#
是的,在tickes.fontSize配置中,您只能对x轴执行此操作
var ctx = document.getElementById("myChart"); var myChart = new Chart(ctx, { type: 'bar', data: { labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"], datasets: [{ label: '# of Votes', data: [12, 19, 3, 5, 2, 3], backgroundColor: [ 'rgba(255, 99, 132, 0.2)', 'rgba(54, 162, 235, 0.2)', 'rgba(255, 206, 86, 0.2)', 'rgba(75, 192, 192, 0.2)', 'rgba(153, 102, 255, 0.2)', 'rgba(255, 159, 64, 0.2)' ], borderColor: [ 'rgba(255,99,132,1)', 'rgba(54, 162, 235, 1)', 'rgba(255, 206, 86, 1)', 'rgba(75, 192, 192, 1)', 'rgba(153, 102, 255, 1)', 'rgba(255, 159, 64, 1)' ], borderWidth: 1 }] }, options: { scales: { yAxes: [{ ticks: { beginAtZero: true } }], xAxes: [{ ticks: { fontSize: 8 } }] } } });
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script> <canvas id="myChart" width="400" height="400"></canvas>
ou6hu8tu2#
对于3.5.1版本,它是:options.scales.x.ticks.font.size = $FONT_SIZE
2条答案
按热度按时间gorkyyrv1#
是的,在tickes.fontSize配置中,您只能对x轴执行此操作
ou6hu8tu2#
对于3.5.1版本,它是:
options.scales.x.ticks.font.size = $FONT_SIZE