I know questions with the same title have been asked multiple times. I have looked at multiple answers and none of them fix my error.
This is my code:
head tag
<script src='/javascripts/jQuery-1.11.3.min.js'></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<!--<script src='/javascripts/highCharts.js'></script>-->
<script src='http://code.highcharts.com/highcharts.js'></script>
I have attempted CDNing and also from my domain (code in highCharts.js
taken straight from http://code.highcharts.com/highcharts.js)
My plugin is also after I've loaded in my jQuery so that's not the error.
When DOM is loaded
$(function() {
buildHighcharts();
});
function buildHighcharts() {
$('#graph_bar_month').highcharts({
....
});
$('#graph_line_year').highcharts({
...
});
$('#graph_bar_teamPercent').highcharts({
...
});
$('#graph_bar_teamActual').highcharts({
...
});
}
HTML
<div class="tab-pane maxHeight" id="show_graph">
<div class="row maxHeight maxWide">
<div id="graph_bar_month" class="col-lg-6 col-md-6 col-sm-6 halfHeight"></div>
<div id="graph_line_year" class="col-lg-6 col-md-6 col-sm-6 halfHeight"></div>
<div id="graph_bar_teamActual" class="col-lg-6 col-md-6 col-sm-6 halfHeight"></div>
<div id="graph_bar_teamPercent" class="col-lg-6 col-md-6 col-sm-6 halfHeight"></div>
</div>
</div>
I have tried cutting it down to only one highchart, as thought multiple might be causing the error, but no luck.
Have tried adding series
data to the chart to try and force it to display but no luck
This is my entire head (I cannot see the error being anywhere else than here):
<head>
<link rel='stylesheet' href='/stylesheets/css/style.css' />
<link rel='stylesheet' href='/stylesheets/css/tables.css' />
<link rel='stylesheet' href='/stylesheets/css/jquery.mCustomScrollbar.css' />
<link rel='stylesheet' href='/stylesheets/css/wrappers.css' />
<link rel='stylesheet' href='/stylesheets/css/queries.css' />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="/javascripts/jquery-1.10.2.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src='/javascripts/jquery.mCustomScrollbar.concat.min.js'></script>
<script src='/javascripts/clock.js'></script>
<script src='/javascripts/fixedHeader.js'></script>
<!--<script src='/javascripts/customLogin.js'></script>-->
<script src='/javascripts/customAlert.js'></script>
<!--<script src='/javascripts/highCharts.js'></script>-->
<script src='http://code.highcharts.com/highcharts.js'></script>
<!--<script src='/javascripts/displayCustomScroll.js'></script>-->
<!--<script src='/javascripts/displayHighcharts.js'></script>-->
<script>
(function($) {
$(window).load(function(){
$(".bottomWrapperTable").mCustomScrollbar({
axis: "y",
theme: "dark",
scrollbarPosition: "outside",
callbacks: {
whileScrolling: function(){
setScroll(this.mcs.left);
},
onScroll: function() {
setStartEndScroll(this.mcs.leftPct);
}
}
});
setInterval('updateClock()', 1000);
});
})(jQuery);
function buildHighcharts() {
$('#graph_bar_month').highcharts({
chart: {
renderTo: 'graph_bar_month',
type: 'bar'
},
title: {
text: '**Current Month**'
},
xAxis: {
categories: ['On Target', 'Below Target', 'Not Entered']
},
yAxis: {
title: {
text: '%'
},
categories: [0, 50, 100]
}
});
$('#graph_line_year').highcharts({
chart: {
type: 'line'
},
title: {
text: '**Current Year**'
},
xAxis: {
categories: ['January', 'February', 'March']
},
yAxis: {
title: {
text: '%'
},
categories: [0, 50, 100]
},
series : [{
name: 'Total % On Target',
data: [1, 2, 3]
}, {
name: 'Total % Below Target',
data: [1, 2, 3]
}, {
name: 'Total % Not Entered',
data: [1, 2, 3]
}]
});
$('#graph_bar_teamPercent').highcharts({
chart: {
type: 'bar'
},
title: {
text: 'Team % On Target'
},
xAxis: {
title: {
text: 'Team'
},
categories: ['Daimler', 'Mclaren', 'Comms Server']
},
yAxis: {
categories: [0, 50, 100],
title: {
text: '%'
}
}
});
$('#graph_bar_teamActual').highcharts({
chart: {
type: 'bar'
},
title: {
text: 'Team % On Target'
},
xAxis: {
title: {
text: 'Team'
},
categories: ['Daimler', 'Mclaren', 'Comms Server']
},
yAxis: {
categories: [0, 50, 500]
}
});
}
$(function() { //$(document).ready()
var url = window.location.href;
buildHighcharts();
if (url.indexOf('?error') != -1) {
Alert.render('Record no longer exists!\nPlease choose another', 'Oops!');
}
$('#createBtn').on('click', function() {
$('#currProdID').val($('#projDrop').val());
$('#currMetrics').submit();
});
$('#fixed-table-head').on('scroll', function(e, val) {
if((-val >= 0) && (val < 10000)) {
this.scrollLeft = -val;
} else if (val === 10000) {
this.scrollLeft = (this.scrollWidth - this.clientWidth);
}
});
if (document.getElementById('projDrop').value != "") {
document.getElementById('createBtn').disabled = false;
}
$('#projDrop').on('change', function() {
document.getElementById('createBtn').disabled = false;
});
});
</script>
</head>
[SOLVED]
My error was that I was calling buildHighcharts
before it had been invoked.
Solution: Called the function in $(window).load()
whilst keeping the invoke outside it