javascript - 未捕获的语法错误 : Unexpected token ILLEGAL in javascript

标签 javascript html css highcharts

我正在尝试使用 Highcharts 图表 API 在网格中创建折线图、柱形图和饼图。但是我收到错误“未捕获的语法错误:意外的 token 非法”。从几个小时开始挠我的头。引用链接:http://www.highcharts.com/demo/com

 <apex:page>
 <script src="https://code.highcharts.com/highcharts.js"></script>
 <script src="https://code.highcharts.com/modules/exporting.js"></script>
 <div id="container" style="min-width: 310px; height: 400px; margin:0 auto"></div>

    <script>
        $(function () {
        $('#container').highcharts({
        title: {
        text: 'Combination chart'
        },
        xAxis: {
            categories: ['Apples', 'Oranges', 'Pears', 'Bananas', 'Plums']
        },
                labels: {
                items: [{
                html: 'Total fruit consumption',
                style: {
                left: '50px',
                top: '18px',
               color: (Highcharts.theme &amp;&amp;Highcharts.theme.textColor)||'black'
                }
            }]
        },
          series: [{
                type: 'column',
                name: 'Jane',
                data: [3, 2, 1, 3, 4]
                }, {
                 type: 'column',
                name: 'John',
               data: [2, 3, 5, 7, 6]
                }, {
                type: 'column',
                name: 'Joe',
                data: [4, 3, 3, 9, 0]
                }, {
                type: 'spline',
                name: 'Average',
                data: [3, 2.67, 3, 6.33, 3.33],
                marker: {
                lineWidth: 2,
                lineColor: Highcharts.getOptions().colors[3],
                fillColor: 'white'
              }
            }, {
            type: 'pie',
            name: 'Total consumption',
            data: [{
                name: 'Jane',
                y: 13,
                color: Highcharts.getOptions().colors[0] 
              }, {
                name: 'John',
                y: 23,
                color: Highcharts.getOptions().colors[1] 
                }, {
                name: 'Joe',
                y: 19,
                color: Highcharts.getOptions().colors[2] 
            }],
            center: [100, 80],
            size: 100,
            showInLegend: false,
            dataLabels: {
                enabled: false
                }
            }]
        });
    });

    </script>
   </apex:page>


    Really appreciate the help.

最佳答案

您的 JavaScript 代码中有一个 HTML 特殊实体字符(& 代表 &)。 试试这个方法:

 <apex:page>
     <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
     <script src="https://code.highcharts.com/highcharts.js"></script>
     <script src="https://code.highcharts.com/modules/exporting.js"></script>
     <div id="container" style="min-width: 310px; height: 400px; margin:0 auto"></div>

        <script>
            $(function () {
            $('#container').highcharts({
            title: {
            text: 'Combination chart'
            },
            xAxis: {
                categories: ['Apples', 'Oranges', 'Pears', 'Bananas', 'Plums']
            },
                    labels: {
                    items: [{
                    html: 'Total fruit consumption',
                    style: {
                    left: '50px',
                    top: '18px',
                   color: (Highcharts.theme && Highcharts.theme.textColor)||'black' // remove the HTML-like "&" encoding...
                    }
                }]
            },
              series: [{
                    type: 'column',
                    name: 'Jane',
                    data: [3, 2, 1, 3, 4]
                    }, {
                     type: 'column',
                    name: 'John',
                   data: [2, 3, 5, 7, 6]
                    }, {
                    type: 'column',
                    name: 'Joe',
                    data: [4, 3, 3, 9, 0]
                    }, {
                    type: 'spline',
                    name: 'Average',
                    data: [3, 2.67, 3, 6.33, 3.33],
                    marker: {
                    lineWidth: 2,
                    lineColor: Highcharts.getOptions().colors[3],
                    fillColor: 'white'
                  }
                }, {
                type: 'pie',
                name: 'Total consumption',
                data: [{
                    name: 'Jane',
                    y: 13,
                    color: Highcharts.getOptions().colors[0] 
                  }, {
                    name: 'John',
                    y: 23,
                    color: Highcharts.getOptions().colors[1] 
                    }, {
                    name: 'Joe',
                    y: 19,
                    color: Highcharts.getOptions().colors[2] 
                }],
                center: [100, 80],
                size: 100,
                showInLegend: false,
                dataLabels: {
                    enabled: false
                    }
                }]
            });
        });

        </script>
  </apex:page>

我也包含了一个 jQuery CDN 引用。我不知道 Highcharts 是否需要它。

关于javascript - 未捕获的语法错误 : Unexpected token ILLEGAL in javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24637195/

相关文章:

javascript - 我应该如何确定苹果可以放置在特定位置?

javascript - ScrollMagic 元素在页面加载时自动触发

javascript - 由于 JS,CSS 未从正确的文件夹加载

html - 如何防止背景位置移动/折叠?

iPhone 移动版 Safari : Portion of content scales by it self

html - 由 anchor 标记组成的菜单在 Internet Explorer 上无法正常工作

javascript - 访问jquery中嵌套函数中外部函数的元素

javascript - 使用谷歌脚本的 Binance API 签名

javascript - 如何在网站中使用天气 API

html - 如何动态更改 :before element in pure CSS? 的字体大小