问题描述
我正在使用create ChartJS 来创建图表.系统提供了在日期范围内搜索数据的功能.完全搜索新的负荷图表时,但是当重点关注图表时,将再次显示旧图表值.要解决该问题,请删除先前的画布内容并使用
I am using create ChartJS for create chart.And system provide facility to search data in date range. When searching new rage load chart corectly, but when focus to chart old chart values display again.To solve that remove previous canvas content and load new canvas using
$('#line').remove();
$('#chart_container').append('<canvas id="line" height="600px" style="margin-top:20px;" ></canvas>');
该修复图正确加载后,但浏览器控制台显示以下错误
After that fix chart load properly, but browser console display bellow error
推荐答案
之所以会发生这种情况,是因为在创建时绑定了事件(调整大小),并且没有检查画布在调整大小处理程序中是否存在.
This happens because the events (resize) are binded at creation and there is no check whether the canvas exists or not in the resize handler.
为了防止出现此问题,您可以修改resize
函数并在其他所有内容之前插入以下行:
In order to prevent this issue, you can modify the resize
function and insert the following line before everything else:
if( !this.canvas ) return;
这篇关于未被捕获的TypeError:无法在ChartJS中读取null的属性"currentStyle"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!