How do I use an element from an array in javascript in html which is declared outside the function? I'm trying to use the elements of the array to create a graph but the graph doesnt show up in the webpage, I do not know why.
<!DOCTYPE HTML>
<html>
<head>
<title>xyz</title>
<script type="text/javascript">
var x1=[],y1=[];
function define(){
x1={"1780330","1716120","1832015","1822602","1878293","1989673","2093379","2121345","2224831","2325575","2387188","2647722"};
y1={"42053.0","51667.5","47647.5","51539.5","49135.3","52750.1","48508.1","42877.4","53483.1","49935.8","45813.1","53521.8"};}
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer",
{
zoomEnabled: true,
title:{
text: e11 "vs" e22
},
animationEnabled: true,
axisX:{
title: xaxis,
valueFormatString: "#",
minimum: 1700000,
maximum: 2700000
},
axisY:{
title: yaxis,
valueFormatString: "#",
minimum: 40000,
maximum: 55000
},
legend: {
verticalAlign: "bottom",
horizontalAlign: "left"
},
data: [
{
type: "scatter",
color: "#778899",
legendText: "Each circle represents one year",
showInLegend: "true",
markerType: "circle",
toolTipContent: "<span style='\"'color: CornflowerBlue;'\"'><strong></strong></span> {x}<br/> <span style='\"'color: ForestGreen;'\"'><strong></strong></span> {y}",
dataPoints: [
{ x: x1[0], y: y1[0] },
{ x: x1[1], y: y1[1] },
{ x: x1[2], y: y1[2] },
{ x: x1[3], y: y1[3] },
{ x: x1[4], y: y1[4] },
{ x: x1[5], y: y1[5] },
{ x: x1[6], y: y1[6] },
{ x: x1[7], y: y1[7] },
{ x: x1[8], y: y1[8] },
{ x: x1[9], y: y1[9] },
{ x: x1[10], y: y1[10] },
{ x: x1[11], y: y1[11] },
]
}
]
});
chart.render();
}
</script>
<script type="text/javascript" src="C:\Users\Rishika\Downloads\canvasjs-1.7.0\canvasjs.min.js"></script>
</head>
<body>
<div id="chartContainer" style="height: 300px; width: 100%;">
</div>
</body>
text: e11 "vs" e22does this work ? Doesn't look like valid JavaScript syntaxcanvasjs.min.jsloading in the browser. Any error in the console?