2

我需要使用prototype.js 进行Web 服务调用,然后使用highchart.js 绘制图表。我按照建议使用了prototype-adapter.js,但如果我尝试同时使用两者(highchart 和原型),我仍然会出错。我创建了一个 jsFiddle

http://jsfiddle.net/j5Grq/6/

$(function () {
var chart;
$(document).ready(function () {
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'line',
            marginRight: 130,
            marginBottom: 25
        },
        title: {
            text: 'Monthly Average Temperature',
            x: -20 //center
        },
        subtitle: {
            text: 'Source: WorldClimate.com',
            x: -20
        },
        xAxis: {
            categories: ['09/10', '09/11', '09/12', '09/13', '09/14']
        },
        yAxis: {
            title: {
                text: 'Temperature (°C)'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            formatter: function () {
                return '<b>' + this.series.name + '</b><br/>' + this.x + ': ' + this.y + '°C';
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -10,
            y: 100,
            borderWidth: 0
        },
        series: [{
            name: 'ABCD',
            data: [648.47, 636.43, 643.97, 640.92]
        }, {
            name: 'ABCD1',
            data: [899.46, 882.80, 893.29, 889.07]
        }, {
            name: 'ABCD2',
            data: [1359.06, 1328.04, 1349.74, 1342.52]
        }]
    });
});

});

如果我删除了prototype.js 和prototype-adapter.js,那么图表绘制得很好,但如果我包含它们,图表就不起作用。我需要prototype.js 来进行Web 服务调用。

请帮忙。

谢谢

4

3 回答 3

0

将你的 jQuery 包装成一个匿名函数,以保护变量不受 Prototype 的干扰。http://jsfiddle.net/amyamy86/s6ms3/

(function($) {

    $.noConflict();
    $(function () {
        $('#contain').highcharts({
         ....
        });
     });

}(jQuery));
于 2014-04-29T17:22:31.747 回答
0

试试这个代码,它将毫无问题地工作。

我刚换

 $(function () {      

为了这

jQuery(function($) { 

这是您的图表的答案。

 http://jsfiddle.net/j5Grq/17/
于 2014-04-29T17:42:49.543 回答
0

它不起作用,因为您使用 $(document).ready(); 这是jquery声明。

于 2013-02-28T12:39:48.433 回答