我正在使用Chart.JS绘制数据集,
但是我的效果很好!
这是我得到的曲线:
这是我的代码:
function plotChart(data, labels) {
var lineChartData = {
"datasets": [{
"data": data,
"pointStrokeColor": "#fff",
"fillColor": "rgba(220,220,220,0.5)",
"pointColor": "rgba(220,220,220,1)",
"strokeColor": "rgba(220,220,220,1)"
}],
"labels": labels
};
var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Line(lineChartData);
}
我怎样才能有直线而不是曲线?
谢谢
根据chartjs.org的文件
你可以在选项中设置'bezierCurve'并在创建图表时传递它.
bezierCurve: false
例如:
var options = {
//Boolean - Whether the line is curved between points
bezierCurve : false
};
var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Line(lineChartData, options);
版本2更新
根据全局选项中的线路配置的更新文档
Name Type Default Description tension Number 0.4 Default bezier curve tension. Set to 0 for no bezier curves.
例如:
var options = {
elements: {
line: {
tension: 0
}
}
};
并且还通过设置lineTension
为0(零)直接在数据集结构中.
Property Type Usage lineTension Number Bezier curve tension of the line. Set to 0 to draw straightlines. This option is ignored if monotone cubic interpolation is used. Note This was renamed from 'tension' but the old name still works.
使用这些属性的示例数据对象如下所示.
var lineChartData = {
labels: labels,
datasets: [
{
label: "My First dataset",
lineTension: 0,
data: data,
}
]
};
您可以使用lineTension选项设置所需的曲线.将0设置为直线.你可以给0-1之间的数字
data: { datasets: [{ lineTension: 0 }] }