【发布时间】:2017-03-29 12:12:30
【问题描述】:
问题:大家好!我正在使用 chart.js 来绘制图表。图表是动态的,有时显示 10 个点,有时可能超过一千个我已经成功应用了一个面板,这样我的点就可以显示在一定距离以便轻松阅读它们。
现在我想知道是否有任何选项可以设置 x 轴网格中点之间的距离。现在它会自动调整点。
我尝试了什么: 我试图通过搜索其他stackoverflow答案来做stepsize和scalewidth,但没有成功。任何形式的帮助将不胜感激。
P.S:我正在使用 chart.js2
这是我的 chartjs 数据集
var data = {
labels: data.graph_date,
datasets: [
{
label: 'Assay Values',
fill: false,
lineTension: 0,
backgroundColor: "rgba(255, 0, 0,1)",
borderColor: "rgba(255, 0, 0,1)",
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderWidth: 1,
borderJoinStyle: 'miter',
pointBorderColor: "rgba(255, 0, 0,1)",
pointBackgroundColor: "#fff",
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(255, 0, 0,1)",
pointHoverBorderColor: "rgba(255, 0, 0,1)",
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 10,
data: data.assay_value,
spanGaps: false
},var options = {
responsive: false,
title: {
display: true,
position: "top",
text: label,
fontSize: 18,
fontColor: "#111"
},
legend: {
display: true,
position: "bottom",
labels: {
fontColor: "#333",
fontSize: 16
}
},
tooltips: {
enabled: true,
mode: 'single',
callbacks: {
label: function(tooltipItems, data) {
var multistringText = ['Assay Value: '+tooltipItems.yLabel];
multistringText.push('Assigned Value: '+assigned_value[tooltipItems.index]);
multistringText.push('Sample ID: '+sample_id[tooltipItems.index]);
return multistringText;
}
}
},
scales:{
yAxes:[{
ticks:{
min:graph_min
}
}],
xAxes: [{
gridLines: {
display:false
}
}]
}
};
if(new_chart[ctx.canvas.id] != null)
new_chart[ctx.canvas.id].destroy();
new_chart[ctx.canvas.id] =new Chart(ctx, {
type: 'line',
data: data,
options: options
});
x轴有这样的数据
[19-Aug-2015,21-Aug-2015,21-Aug-2015,21-Aug-2015,21-Aug-2015,22-Aug-2015,27-Aug-2015,29-Aug-2015,1-Sep-2015,2-Sep-2015,3-Sep-2015,]
y轴数据是这样的
[0.1,0.05,0.89,0.89,0.79,0.58,0.68,0.25,0.98]
【问题讨论】:
-
stepSize 确实有效,你的意思是你没有成功?
-
kristjan 它不适用于 xaxis 它只适用于 yaxis
-
你能发布你的整个 chart.js 配置和你的数据样本吗?这是提供具体答案所需要的。
标签: javascript html charts chart.js chart.js2