我正在爲我的項目使用Polymer和HighCharts。 我使用的代碼是:HighCharts未在聚合物頁面上渲染
HTML:
<div class="container" layout vertical center>
<paper-shadow z="1" class="span-shadow">
<post-card id="card1">
<img width="70" height="70" src="../images/graphex.jpg">
<h2>Some Graph</h2>
<div id="container2" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
</post-card>
</paper-shadow>
和JS:
$(function() {
$('#container2').highcharts({
title: {
text: 'Monthly Average Temperature',
x: -20 //center
},
subtitle: {
text: 'Source: WorldClimate.com',
x: -20
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
text: 'Temperature (°C)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: '°C'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [{
name: 'Tokyo',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}, {
name: 'New York',
data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
}, {
name: 'Berlin',
data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
}, {
name: 'London',
data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
}]
});
});
不過,雖然正確生成卡,裏面的圖形是不可見的,我得到這個錯誤:
TypeError: undefined is not an object (evaluating 'HighchartsAdapter.addEvent') (anonymous function)highcharts.js:304:237 (anonymous function)highcharts.js:306:162 global codehighcharts.js:322 exporting.js:9
和
ReferenceError: Can't find variable: $
如何解決此錯誤?
謝謝!
'$ is not defined'是因爲你的頁面沒有jQuery。在頁面上使用Jquery腳本,然後重試。 – 2015-02-24 11:10:53
'' – 2015-02-24 11:12:09
任何更新? – 2015-02-25 05:58:43