【发布时间】:2017-08-16 06:50:22
【问题描述】:
开始,I have made a short video to show exactly what I'm running into。
总结视频:在使用 Chart.js (2.6.0) 时,我可以毫无问题地创建图表;但是当我将鼠标悬停在条/点上时,图表将调整其元素的大小并闪烁。奇怪的是,它完全不一致。有时当我刷新时,它根本没有这种行为;但是如果我将鼠标悬停在某个东西上并且它开始执行它,它不会停止,直到我再次刷新或关闭选项卡(它也与此不一致)。发生这种情况时,我不会更改代码中的任何内容,它会自行完成。
为了修复它,我在 SO 上引用了许多其他线程,以及 Chart.js 文档。在我的解决方案中:我已经将指定的高度/宽度添加到创建图表的 Divs & Canvas 中;设置Animation时长为0,Hover Animation时长为0,Responsive Animation时长为0;我确保 Responsive 设置为 true,并保持保持 Aspect Ratio 为 true,更改了工具提示模式......我已经尝试了所有这些,以及其他似乎几乎没有影响的小事情。
我被难住了!
这是我的图表代码之一(没有我如何获取 JSON 数据等,只是图表):
new Chart($("#runwayChart"), {
type: "horizontalBar",
data: {
labels: runwayLabels,
datasets: [{
label: "Months Left", fill: true,
backgroundColor: "#3333ff",
borderColor: "#3333ff",
data: score
}, {
label: "Expenses",
fill: true,
backgroundColor: "#aa2222",
borderColor: "#aa2222",
data: expenses
}, {
label: "Revenue",
fill: true,
backgroundColor: "#2222aa",
borderColor: "#2222aa",
data: revenues
}]
},
options: {
tooltips: {
mode: 'index'
},
responsive: true,
maintainAspectRatio: true,
animation: {
duration: 0,
},
hover: {
animationDuration: 0,
},
responsiveAnimationDuration: 0
}
});
感谢大家的帮助!
谢谢 =)
【问题讨论】:
-
您的图表代码是否在 ajax 成功回调中?
-
我们正在使用 Angular,尤其是本节是 .then() 的一部分,如果我们的 REST 请求成功,则会触发。
标签: javascript jquery chart.js2