gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 03:42:41 25 4
gpt4 key购买 nike

我正在尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com