Question

I have the following code in an html file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div id=0 style='width:400px; height:400px'></div>

<script type='text/javascript' src='https://dl.dropboxusercontent.com/u/93241685/jquery.1.9.1.min.js'></script>
<script type='text/javascript' src='https://dl.dropboxusercontent.com/u/93241685/highcharts.js'></script>

<script>
$(function () {
$('#0').highcharts({
chart: {type: 'area',plotBackgroundColor:'white',plotBorderWidth: '',plotShadow: true,zoomType:'undefined'},
title: {text:'TTT'},
xAxis: {title: {text:'trX'}},
yAxis: {title: {text:'Ygrg'}},
tooltip: {pointFormat: '{series.name}  {point.x}'},
});});

var chart = $('#0').highcharts();
chart.addSeries({
name: 'S1',
data: [1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6]
}, false);
chart.redraw();

</script>
</body>
</html>

When i run this, only the div appear with the chart title on top. Nothing else! not even the xAxis title or yAxis title appear. Now, the interesting thing is, when i tried to run it on JSFiddle, it ran perfectly displaying the graph. JSFiddle link is also given below. What possibly can be the problem doing it in an html file, i tried removing extra bits from file and possibly everything but still no use. Kindly help.

http://jsfiddle.net/5fway/

Was it helpful?

Solution

try to include it inside document.ready() because inside jsfiddle you indicate to run code jquery onload (like document.ready()) like this:

$(document).ready(function(){
  $('#0').highcharts({
    chart: {type: 'area',plotBackgroundColor:'white',plotBorderWidth: '',plotShadow: true,zoomType:'undefined'},
    title: {text:'TTT'},
    xAxis: {title: {text:'trX'}},
    yAxis: {title: {text:'Ygrg'}},
    tooltip: {pointFormat: '{series.name}  {point.x}'},
  });

  var chart = $('#0').highcharts();
  chart.addSeries({
    name: 'S1',
    data: [1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6]
  }, false);
  chart.redraw();
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top