On Page With Numerous HighCharts, One Particular Chart Not Displaying.

I’m very new to coding, but have been really trying lately to learn how to use HighCharts. I have a WordPress page set up that shows 5 or 6 different HighCharts. They all work fine!

Except for one. This particular chart just leaves a big blank space where it is supposed to appear. It works in JSFiddle (as it should, since I’m just using HighChart’s boilerplate code).

Read More

See here: http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/bar-negative-stack/.

When I run my browser error console on my wordpress page where the chart is supposed to be, it says:

TypeError: $(…).highcharts is not a function

and points specifically to this line in the code:

$(‘#container6’).highcharts({

Here’s the full actual code for the chart:

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/highcharts-more.js"></script>
<script src="http://code.highcharts.com/modules/solid-gauge.js"></script>
</head>

<script>
$(function () {
// Age categories
var categories = ['0-4', '5-9', '10-14', '15-19',
        '20-24', '25-29', '30-34', '35-39', '40-44',
        '45-49', '50-54', '55-59', '60-64', '65-69',
        '70-74', '75-79', '80-84', '85-89', '90-94',
        '95-99', '100 + '];
$(document).ready(function () {
    $('#container6').highcharts({
        chart: {
            type: 'bar'
        },
        title: {
            text: 'Population pyramid for Germany, 2015'
        },
        subtitle: {
            text: 'Source: <a href="http://populationpyramid.net/germany/2015/">Population Pyramids of the World from 1950 to 2100</a>'
        },
        xAxis: [{
            categories: categories,
            reversed: false,
            labels: {
                step: 1
            }
        }, { // mirror axis on right side
            opposite: true,
            reversed: false,
            categories: categories,
            linkedTo: 0,
            labels: {
                step: 1
            }
        }],
        yAxis: {
            title: {
                text: null
            },
            labels: {
                formatter: function () {
                    return Math.abs(this.value) + '%';
                }
            }
        },

        plotOptions: {
            series: {
                stacking: 'normal'
            }
        },

        tooltip: {
            formatter: function () {
                return '<b>' + this.series.name + ', age ' + this.point.category + '</b><br/>' +
                    'Population: ' + Highcharts.numberFormat(Math.abs(this.point.y), 0);
            }
        },

        series: [{
            name: 'Male',
            data: [-2.2, -2.2, -2.3, -2.5, -2.7, -3.1, -3.2,
                -3.0, -3.2, -4.3, -4.4, -3.6, -3.1, -2.4,
                -2.5, -2.3, -1.2, -0.6, -0.2, -0.0, -0.0]
        }, {
            name: 'Female',
            data: [2.1, 2.0, 2.2, 2.4, 2.6, 3.0, 3.1, 2.9,
                3.1, 4.1, 4.3, 3.6, 3.4, 2.6, 2.9, 2.9,
                1.8, 1.2, 0.6, 0.1, 0.0]
        }]
    });
});

});
</script>
<div id="container6" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"></div>

I’m so appreciative of any help I can get. I’ve tried everything I can think of, and scoured StackOverflow for similar problems. But nothing so far has worked.

Related posts

2 comments

  1. Try yo use following code instead of $(‘#container6’).Highcharts({…});

    var chart = new Highcharts.Charts({
        chart:{
            renderTo:'container6',
            type: 'bar'
        },
        //other options
    });
    

Comments are closed.