在有许多高图的页面上,一个特定的图表不显示

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

本文关键字:一个 显示 许多高      更新时间:2023-09-26

我对编码很陌生,但最近一直在努力学习如何使用HighCharts。我有一个Wordpress页面设置,显示5或6个不同的HighCharts。它们都很好用!

除了一个。这个特殊的图表只是在它应该出现的地方留下了一个很大的空白。它在JSFiddle中工作(应该是这样,因为我只是使用HighChart的样板代码)。

请看这里:http://jsfiddle.net/gh/get/jquery/1.9.1/hililide-software/highcharts.com/tree/master/samples/highcharts/demo/bar-negative-stack/。

当我在我的wordpress页面上运行浏览器错误控制台时,图表应该在哪里,它说:

TypeError: $(…)。Highcharts不是一个函数

,并特别指向代码中的这一行:

$ (' # container6 ') .highcharts ({

这是图表的完整实际代码:

<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>
我很感激我能得到的任何帮助。我已经尝试了我能想到的所有方法,并在StackOverflow上搜索类似的问题。但到目前为止,一切都没有奏效。

尝试使用以下代码代替$('#container6').Highcharts({…});

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

删除行:

$(document).ready(function () {

和在container6中的JavaScript代码图之后删除相应的

});

在此之后-一切都应该正常工作:http://jsfiddle.net/e08Lng1g/