我需要使用prototype.js进行Web服务调用,然后使用highchart.js绘制图表。 我按照建议使用prototype-adapter.js,但如果我尝试同时使用两者(高图和原型),我仍然会收到错误。 我创建了一个jsFiddle
$(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服务调用。
请帮忙。
三江源
答案 0 :(得分:0)
它不起作用,因为你使用$(document).ready();这是jquery声明。
答案 1 :(得分:0)
将jQuery包装到一个匿名函数中,以保护变量免受Prototype的干扰。 http://jsfiddle.net/amyamy86/s6ms3/
(function($) {
$.noConflict();
$(function () {
$('#contain').highcharts({
....
});
});
}(jQuery));
答案 2 :(得分:0)
尝试使用此代码,可以顺利运行。
我刚刚更换了
$(function () {
这个
jQuery(function($) {
以下是图表的答案。
http://jsfiddle.net/j5Grq/17/