[英]regarding FLOT CHARTS API Error :Cannot read property 'length' of undefined
嗨,這是我的FLOT Charts API代碼。 我正在獲取圖形,但是正在獲取上述錯誤。 這是我的代碼:
JavaScript的:
$(function () {
var a1 = [
[0, 1],
[1, 2],
[2, 6],
[3, 9],
[4, 5]
];
var a2 = [
[0, 4],
[1, 5],
[2, 1],
[3, 7],
[4, 7]
];
var data = [{
label: "Pre Transformation",
data: a1
}, {
label: "Post Transformation",
data: a2
}];
$.plot($("#consolidate1"), data, {
series: {
bars: {
show: true,
barWidth: 0.13,
order: 1,
align: "center"
}
},
xaxis: {
ticks: [
[0, "Overall"],
[1, "SEA"],
[2, "INDIA"],
[3, "NEA"],
[4, "PZ"]
],
tickLength: 0
},
grid: {
hoverable: true,
clickable: true,
labelMargin: 15
},
valueLabels: {
show: false
}
});
});
var previousPoint = null,
previousLabel = null;
function showTooltip(x, y, color, contents) {
$('<div id="tooltip">' + contents + '</div>').css({
position: 'absolute',
display: 'none',
top: y - 40,
left: x - 120,
border: '2px solid ' + color,
padding: '3px',
'font-size': '9px',
'border-radius': '5px',
'background-color': '#fff',
'font-family': 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
opacity: 0.9
}).appendTo("body").fadeIn(200);
}
$("#consolidate1").on("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.dataIndex;
var y = item.datapoint[1];
var color = item.series.color;
//console.log(item.series.xaxis.ticks[x].label);
showTooltip(item.pageX,
item.pageY,
color,
"<strong>" + item.series.label + "</strong><br>" + item.series.xaxis.ticks[x].label + ": <strong>" + y + "</strong>");
}
} else {
$("#tooltip").remove();
previousPoint = null;
}
});
HTML代碼:
<div>
<p>Yearly Energy Consumption</p>
<div id="consolidate1" style="width:500px;height:300px;"></div>
</div>
小提琴中的代碼。
我無法弄清楚為什么會出現此錯誤。
我收到了類似的錯誤...在調試時,我發現錯誤指向“〜/ float.js”...。然后,我檢查了我的代碼,有另一個圖表正在嘗試繪制,並且針對該圖表我注釋掉了圖表的HTML部分。.所以我遇到了上述錯誤。
我固定的方式是:注釋掉$ .plot()其他圖表。
希望這可以對某人有所幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.