Javascript hideColumns[1]时出现Google图表错误
我正在使用jquery创建google线形图,用于隐藏/显示数据列。 但当单击第一个数据复选框时,我陷入了这个问题,使用hideColumns总是错误的,但如果hideColumns[2]和hideColumns[3]不是错误的话Javascript hideColumns[1]时出现Google图表错误,javascript,jquery,html,google-visualization,Javascript,Jquery,Html,Google Visualization,我正在使用jquery创建google线形图,用于隐藏/显示数据列。 但当单击第一个数据复选框时,我陷入了这个问题,使用hideColumns总是错误的,但如果hideColumns[2]和hideColumns[3]不是错误的话 $(document).ready(function () { // do stuff on "ready" event $(".checkbox").change(function() {
$(document).ready(function () {
// do stuff on "ready" event
$(".checkbox").change(function() {
view = new google.visualization.DataView(data);
view.setColumns([0, 1,
{ calc: "stringify",
sourceColumn: 1,
type: "string",
role: "annotation" },2,
{ calc: "stringify",
sourceColumn: 2,
type: "string",
role: "annotation" },3,
{ calc: "stringify",
sourceColumn: 3,
type: "string",
role: "annotation" }]);
if(!$("#kolom1").is(':checked'))
view.hideColumns([1]);
if(!$("#kolom2").is(':checked'))
view.hideColumns([2]);
if(!$("#kolom3").is(':checked'))
view.hideColumns([3]);
chart.draw(view, options);
});
});
chrome中的错误表示:
“未能在“节点”上执行“replaceChild”
但如果其他复选框(hideColumns[2]和hideColumns[3])没有问题,如何修复它?您可以在下面的JSFIDLE上进行尝试:
经过反复试验,我用下面的代码解决了自己的问题
$(document).ready(function () {
// do stuff on "ready" event
$(".checkbox").change(function() {
view = new google.visualization.DataView(data);
var tes =[0];
if($("#kolom1").is(':checked')) {
tes.push(1,
{ calc: "stringify",
sourceColumn: 1,
type: "string",
role: "annotation" }); }
if($("#kolom2").is(':checked'))
{
tes.push(2,
{ calc: "stringify",
sourceColumn: 2,
type: "string",
role: "annotation" });
}
if($("#kolom3").is(':checked'))
{
tes.push(3,
{ calc: "stringify",
sourceColumn: 3,
type: "string",
role: "annotation" });
}
view.setColumns(tes);
chart.draw(view, options);
});
});
希望有用