简体   繁体   English

基本Javascript:如何在Highcharts示例中链接HTML和Javascript?

[英]Basic Javascript: How can I link my HTML and Javascript on a Highcharts example?

I'm sorry for the basic question but I googled around and I couldn't get my simple task working. 对于基本问题,我感到抱歉,但是我四处搜寻,无法完成我的简单任务。

I wanted to implement the Pie Chart Gradient example of Highcharts ( http://www.highcharts.com/demo/pie-gradient ), so I copy the javascript into a piechart_gradient.js : 我想实现Highcharts( http://www.highcharts.com/demo/pie-gradient )的饼图渐变示例,所以我将javascript复制到piechart_gradient.js

$(function () {

        // Radialize the colors
        Highcharts.getOptions().colors = Highcharts.map(Highcharts.getOptions().colors, function(color) {
            return {
                radialGradient: { cx: 0.5, cy: 0.3, r: 0.7 },
                stops: [
                    [0, color],
                    [1, Highcharts.Color(color).brighten(-0.3).get('rgb')] // darken
                ]
            };
        });

        // Build the chart
        $('#container').highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },
            title: {
                text: 'Browser market shares at a specific website, 2010'
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        color: '#000000',
                        connectorColor: '#000000',
                        formatter: function() {
                            return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
                        }
                    }
                }
            },
            series: [{
                type: 'pie',
                name: 'Browser share',
                data: [
                    ['Firefox',   45.0],
                    ['IE',       26.8],
                    {
                        name: 'Chrome',
                        y: 12.8,
                        sliced: true,
                        selected: true
                    },
                    ['Safari',    8.5],
                    ['Opera',     6.2],
                    ['Others',   0.7]
                ]
            }]
        });
    });

Then I place the given HTML lines into my web server's index.php , along with an extra line to include the local javascript: 然后,将给定的HTML行放入Web服务器的index.php ,并在其中添加一行以包含本地javascript:

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript" src="piechart_gradient.js"></script>

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

And I just get a blank page. 我只是得到一个空白页。 Shouldn't there be a single pie chart on localhost ? localhost上不应该有一个饼图吗?

EDIT: New HTML index.php : 编辑:新的HTML index.php

<!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">

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script type="text/javascript" src="piechart.js"></script>

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

Same results still , getting a blank page on localhost 结果仍然相同 ,在localhost上获得空白页

you are missing references to jquery 您缺少对jquery引用

<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>

look at this DEMO 看这个演示

AH HAAAAA AH HAAAAA

i know what your are doing 我知道你在做什么

you copied and past jquery reference after the Highcharts right?! 您在Highcharts之后复制并通过了jquery参考,对吗? you need the jquery at the top 你需要顶部的jquery

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

You are missing a reference to jQuery. 您缺少对jQuery的引用。 You should include that as well. 您也应该包括在内。

EDIT: You need to include jQuery before highcharts. 编辑:您需要在highcharts之前包含jQuery。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将我的 javascript 正确链接到我的 html 表单? - How can I correctly link my javascript to my html form? 无法弄清楚如何将我的 JavaScript 链接到我的 html 中 - Can't figure out how to link my JavaScript into my html 如何将我的 javascript 文件与 html 链接? 我认为我已正确链接但无法正常工作? - how can i link my javascript file with html???? I think i have linked properly but not working? 如何改进我的 Javascript/jQuery 逻辑? 包含示例 - How can I improve my Javascript/jQuery logic? Example included 如何在 Javascript 中插入外部 Javascript 链接(例如在 VS-Code 中),因为它已插入 Codepen? - How can I insert an External Javascript link in Javascript(for Example in VS-Code) as it is inserted in Codepen? 如何将JavaScript函数链接到HTML元素? - How do I link my JavaScript function to an HTML element? 我如何将我的JavaScript链接到此html才能工作 - How do I link my javascript to this html to work JavaScript - 如何在所有 html 行中运行 javascript - JavaScript - How can I run the javascript in all my html rows 使用Javascript选择链接时,如何隐藏HTML元素? - How can I hide a HTML element when a link is selected with Javascript? 如何将JavaScript变量链接到HTML值? - How can I link a JavaScript variable to a HTML value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM