gpt4 book ai didi

javascript - 引用错误 : $ is not defined for original flot library

转载 作者:行者123 更新时间:2023-11-30 08:07:19 25 4
gpt4 key购买 nike

各位,我在原始 flot.js 库中遇到了这个错误。我想知道这部分脚本有什么问题?*错误是来自 Firefox 的 shwon Fire bug错误消息是:

ReferenceError: $ is not defined

$(document).ready(function () {

开始声称是错误代码的行是:

$(document).ready(function () {
$.plot($("#flot-placeholder1"), dataset, options);
$("#flot-placeholder1").UseTooltip();
});

下面是错误行之前的内容:

 <script>
//******* 2012 Gold Price Chart
var data1 = [
[gd(2012, 0, 1), 1652.21], [gd(2012, 1, 1), 1742.14], [gd(2012, 2, 1), 1673.77], [gd(2012, 3, 1), 1649.69],
[gd(2012, 4, 1), 1591.19], [gd(2012, 5, 1), 1598.76], [gd(2012, 6, 1), 1589.90], [gd(2012, 7, 1), 1630.31],
[gd(2012, 8, 1), 1744.81], [gd(2012, 9, 1), 1746.58], [gd(2012, 10, 1), 1721.64], [gd(2012, 11, 2), 1684.76]
];
var data2 = [
[gd(2012, 0, 1), 0.63], [gd(2012, 1, 1), 5.44], [gd(2012, 2, 1), -3.92], [gd(2012, 3, 1), -1.44],
[gd(2012, 4, 1), -3.55], [gd(2012, 5, 1), 0.48], [gd(2012, 6, 1), -0.55], [gd(2012, 7, 1), 2.54],
[gd(2012, 8, 1), 7.02], [gd(2012, 9, 1), 0.10], [gd(2012, 10, 1), -1.43], [gd(2012, 11, 2), -2.14]
];
var dataset = [
{ label: "Gold Price", data: data1, points: { symbol: "triangle"} },
{ label: "Change", data: data2, yaxis: 2 }
];
var options = {
series: {
lines: {
show: true
},
points: {
radius: 3,
fill: true,
show: true
}
},
xaxis: {
mode: "time",
tickSize: [1, "month"],
tickLength: 0,
axisLabel: "2012",
axisLabelUseCanvas: true,
axisLabelFontSizePixels: 12,
axisLabelFontFamily: 'Verdana, Arial',
axisLabelPadding: 10
},
yaxes: [{
axisLabel: "Gold Price(USD)",
axisLabelUseCanvas: true,
axisLabelFontSizePixels: 12,
axisLabelFontFamily: 'Verdana, Arial',
axisLabelPadding: 3,
tickFormatter: function (v, axis) {
return $.formatNumber(v, { format: "#,###", locale: "us" });
}
}, {
position: "right",
axisLabel: "Change(%)",
axisLabelUseCanvas: true,
axisLabelFontSizePixels: 12,
axisLabelFontFamily: 'Verdana, Arial',
axisLabelPadding: 3
}
],
legend: {
noColumns: 0,
labelBoxBorderColor: "#000000",
position: "nw"
},
grid: {
hoverable: true,
borderWidth: 2,
borderColor: "#633200",
backgroundColor: { colors: ["#ffffff", "#EDF5FF"] }
},
colors: ["#FF0000", "#0022FF"]
};

=================更新============================= ========================大家好。感谢你的回答!这是我加载脚本的顺序(加载正确,因为我在 DW CS4 中测试它1.jquery-1.8.3.min.js2.jquery.flot.min.js”3.jquery.flot.time.js”4.jquery.flot.symbol.js5.jquery.flot.axislabels.js6.jshashtable-2.1.js7.jquery.numberformatter-1.2.3.min.js

所以我认为顺序应该不是问题,它遵循教程告诉我在这里做: http://www.pureexample.com/jquery-flot-tutorial-how-to-make-a-jquery-flot-line-chart.html

我还发现这些代码被 Firefox/firebug 阻止了,也许它有帮助。停止点放在代码的第 2 行前面 --> '$(this).bind("plot...'.

$.fn.UseTooltip = function () {
$(this).bind("plothover", function (event, pos, item) {
if (item) {
if ((previousLabel != item.series.label) || (previousPoint != item.dataIndex)) {
previousPoint = item.dataIndex;
previousLabel = item.series.label;
$("#tooltip").remove();
var x = item.datapoint[0];
var y = item.datapoint[1];
var color = item.series.color;
var month = new Date(x).getMonth();
//console.log(item);
if (item.seriesIndex == 0) {
showTooltip(item.pageX,
item.pageY,
color,
"<strong>" + item.series.label + "</strong><br>" + monthNames[month] + " : <strong>" + y + "</strong>(USD)");
} else {
showTooltip(item.pageX,
item.pageY,
color,
"<strong>" + item.series.label + "</strong><br>" + monthNames[month] + " : <strong>" + y + "</strong>(%)");
}
}
} else {
$("#tooltip").remove();
previousPoint = null;
}
});
};

谢谢。

凯文的进一步问题在他的回答的评论下被问到....

最佳答案

错误在这里:

$(document)

$ 未定义。这意味着您要么没有包括 jQuery,包括得太晚了,要么错误地使用了 $.noConflict()

更具体地说,$ === undefined,undefined 不是函数,因此无法执行。

关于javascript - 引用错误 : $ is not defined for original flot library,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16090976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com