您好,我是图表的新手,这是我的chartjs图表,当前正在运行,但是以清晰的线条显示,我想在此图表上使其平滑的曲线线。有什么想法吗?
function statistics(data) {
if ($('#stats-currency').length > 0) {
if (typeof(stats_currency) !== 'undefined') {
stats_currency.destroy();
}
if (typeof(data) == 'undefined') {
var currency = $('select[name="currency"]').val();
$.get(admin_url + 'home/stats_currency/' + currency, function(response) {
stats_currency = new Chart($('#stats-currency'), {
type: 'line',
data: response,
options: {
responsive:true,
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
}
}]
},
},
});
}, 'json');
} else {
stats_currency = new Chart($('#stats-currency'), {
type: 'line',
data: data,
options: {
responsive: true,
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
}
}]
},
},
});
}
答案 0 :(得分:0)
这可以通过需要在数据集中定义的选项lineTension
来完成。选择一个低于1的值。
datasets: [{
...
lineTension: 0.8
}]
但是,默认情况下,由于Chart.js documentation的默认值是0.4
,因此您应该已经看到弯曲的平滑线。
lineTension
:直线的贝塞尔曲线张力。设置为0绘制直线。请注意,如果将
steppedLine
的值设置为false
以外的任何值,则lineTension
将被忽略。