score:2

Accepted answer

it sounds like you're loading the same javascript file (which contains the configurations for both of your charts) in both of your pages. the problem is since you're using a single javascript file with two chart definitions, the chart you try to create that doesn't exist in the html is throwing an error because you are passing in an empty context.

window.onload = function(){
  //piechart (this will be null on page2.html)
  var piectx = document.getelementbyid("piechart"); 

  // you are passing in a null piectx on page2.html because there is no element with an id = "piechart"
  var mypiechart = new chart(piectx, pievar); 

  //linechart (this will be null on page1.html)
  var linectx = document.getelementbyid("linechart"); 

  // you are passing in a null linectx on page1.html because there is no element with an id = "linechart"
  var mylinechart = new chart(linectx, linevar); 
};

you should either split your javascript file into two files so that the first page only includes the definition for the first chart and the second page only includes the definition for the second chart. or, add some conditions to prevent trying to create the empty chart (like this).

window.onload = function(){
  //piechart (this will be null on page2.html)
  var piectx = document.getelementbyid("piechart"); 

  if (piechart) {
    var mypiechart = new chart(piectx, pievar); 
  }

  //linechart (this will be null on page1.html)
  var linectx = document.getelementbyid("linechart"); 

  if (linechart) {
    var mylinechart = new chart(linectx, linevar); 
  }
};

Related Query

More Query from same tag