为什么这个代码不能在我的网站上运行

时间:2015-01-17 02:04:50

标签: jsfiddle

我试图通过插入'Raw HTML'功能将此代码添加到我的网站,使用sandvox构建。添加代码后,我只是在网站上看到一个空白框。我希望有一些方法可以得到一些帮助。谢谢你的帮助。

<html>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
 <script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>


<div id="container" style="min-width: 500px; height: 400px; margin: 0 auto"></div>

<script>
$(function () {
    $('#container').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: 'Prevalence of Performance Enhancing Drug Use By Sport'
        },
        subtitle: {
            text: 'Source: <a href="http://www.samuelwbennett.com">getfast</a>'
        },
        xAxis: {
            type: 'category',
            labels: {
                rotation: -45,
                style: {
                    fontSize: '13px',
                    fontFamily: 'Verdana, sans-serif'
                }
            }
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Prevalence (%)'
            }
        },
        legend: {
            enabled: false
        },
        tooltip: {
            pointFormat: 'PED Prevalence: <b>{point.y:.1f} %</b>'
        },
        series: [{
            name: 'Prevalence',
            data: [
                ['WADA All Pros', 2],
                ['Child Athletes', 4],
                ['HS Football', 6.3],
                ['HS Seniors All Sports', 6.6],
                ['Amatuer Weight-lifters', 8.2],
                ['American Football', 9],
                ['Baseball', 9.4],
                ['Research Estimate All Pros', 10.2],
                ['Top 100 Sprinters (running)', 40],
                ['Professional Bodybuilders', 54],
                ['Tour de France Winners', 79],

            ],
            dataLabels: {
                enabled: true,
                rotation: -90,
                color: '#FFFFFF',
                align: 'right',
                x: 4,
                y: -15,
                style: {
                    fontSize: '13px',
                    fontFamily: 'Verdana, sans-serif',
                    textShadow: '0 0 3px black'
                }
            }
        }]
    });
});

 </hmtl>

2 个答案:

答案 0 :(得分:0)

在highcharts js之前放置jQuery脚本,不要忘记关闭<script>标记

<html>
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>


<div id="container" style="min-width: 500px; height: 400px; margin: 0 auto"></div>

<script>
$(function () {
    $('#container').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: 'Prevalence of Performance Enhancing Drug Use By Sport'
        },
        subtitle: {
            text: 'Source: <a href="http://www.samuelwbennett.com">getfast</a>'
        },
        xAxis: {
            type: 'category',
            labels: {
                rotation: -45,
                style: {
                    fontSize: '13px',
                    fontFamily: 'Verdana, sans-serif'
                }
            }
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Prevalence (%)'
            }
        },
        legend: {
            enabled: false
        },
        tooltip: {
            pointFormat: 'PED Prevalence: <b>{point.y:.1f} %</b>'
        },
        series: [{
            name: 'Prevalence',
            data: [
                ['WADA All Pros', 2],
                ['Child Athletes', 4],
                ['HS Football', 6.3],
                ['HS Seniors All Sports', 6.6],
                ['Amatuer Weight-lifters', 8.2],
                ['American Football', 9],
                ['Baseball', 9.4],
                ['Research Estimate All Pros', 10.2],
                ['Top 100 Sprinters (running)', 40],
                ['Professional Bodybuilders', 54],
                ['Tour de France Winners', 79],

            ],
            dataLabels: {
                enabled: true,
                rotation: -90,
                color: '#FFFFFF',
                align: 'right',
                x: 4,
                y: -15,
                style: {
                    fontSize: '13px',
                    fontFamily: 'Verdana, sans-serif',
                    textShadow: '0 0 3px black'
                }
            }
        }]
    });
});
</script>

</hmtl>

答案 1 :(得分:0)

您在Highcharts脚本末尾缺少结束</script>标记。在加载Highcharts脚本之前添加结束标记并确保加载jQuery应该很有效。

所以它应该是:

<html>
<head>
    <script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
    <script src="http://code.highcharts.com/highcharts.js"></script>
    <script src="http://code.highcharts.com/modules/exporting.js"></script>

    <script>

       <!-- your Highcharts script here... -->

    </script>
</head>

<body>
    <div id="container" style="min-width: 500px; height: 400px; margin: 0 auto"></div>
</body>
</html>

可以看到一个工作示例here