0

我需要使用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

H

        <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]
                            ]
                        }]
                    }); 
4

2 回答 2

0

我建议使用 id 而不是图表的类。其次,您应该在加载 DOM 后使用$(document).ready()or$(function () {});生成图表。 http://jsfiddle.net/3WeZr/1/

于 2013-05-30T14:25:27.040 回答
0

问题是我使用的是旧版本的 highcharts.js!

现在效果很好:)

于 2013-06-04T14:50:46.317 回答