我需要使用Highcharts
。我尝试过下面的代码,但它给了我error
:
Uncaught TypeError: Object [object Object] has no method 'highcharts' Hse:178
highChart Hse:178
(anonymous function) Hse:148
b.Callbacks.c jquery-1.9.1.js:3
b.Callbacks.p.fireWith jquery-1.9.1.js:3
b.extend.ready jquery-1.9.1.js:3
ħ
<div>
<span class="inlinesparkline"></span>
<span class="container"></span>
</div>
<script type="text/javascript" src="@Url.Content("/Scripts/ext/highcharts.js")"></script>
<script type="text/javascript">
//KPI Charts
$(function () {
highChart();
function highChart() {
//Highcharts
$('.container').highcharts({
chart: {
type: 'spline',
renderTo: 'container'
},
title: {
text: 'Snow depth in the Vikjafjellet mountain, Norway'
},
subtitle: {
text: 'An example of irregular time data in Highcharts JS'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { // don't display the dummy year
month: '%e. %b',
year: '%b'
}
},
yAxis: {
title: {
text: 'Snow depth (m)'
},
min: 0
},
tooltip: {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
Highcharts.dateFormat('%e. %b', this.x) + ': ' + this.y + ' m';
}
},
series: [{
name: 'Winter 2007-2008'
data: [
[Date.UTC(1970, 9, 27), 0],
[Date.UTC(1970, 10, 10), 0.6],
[Date.UTC(1971, 1, 18), 1.80],
[Date.UTC(1971, 1, 24), 1.92],
[Date.UTC(1971, 2, 4), 2.49]
]}, {
name: 'Winter 2008-2009',
data: [
[Date.UTC(1970, 9, 18), 0],
[Date.UTC(1971, 3, 19), 1.6],
[Date.UTC(1971, 4, 25), 0.6],
[Date.UTC(1971, 4, 31), 0.35],
[Date.UTC(1971, 5, 7), 0]
]
}, {
name: 'Winter 2009-2010',
data: [
[Date.UTC(1971, 1, 23), 0.77],
[Date.UTC(1971, 3, 18), 0.94],
[Date.UTC(1971, 3, 24), 0.9],
[Date.UTC(1971, 4, 16), 0.39],
[Date.UTC(1971, 4, 21), 0]
]
}]
});
答案 0 :(得分:0)
我喜欢使用id而不是class来表示图表。其次,您应该在加载DOM后使用$(document).ready()
或$(function () {});
生成图表。
http://jsfiddle.net/3WeZr/1/
答案 1 :(得分:0)
问题是我使用旧版本的highcharts.js!
现在它运作良好:)