我正在尝试使用flot.js绘制一些电流f。问题是我无法在代码中使用flot.js。 我正在使用的jQuery版本是3.4.0。 Flot版本是0.8.3
该代码可以在不包含flot库的情况下正常运行。
我的index.php
<html>
<head>
<title>Jupiter</title>
<link rel="icon" href="./pics/jupiter.png">
<link rel="stylesheet" href="./css/bootstrap.min.css">
<link rel="stylesheet" href="./css/frontend.css">
<link rel="stylesheet" href="./css/bootstrap-toggle.min.css">
<link rel="stylesheet" href="./css/jquery-confirm.min.css">
<script src="./js/jquery.min.js"></script>
<script src="./js/bootstrap.min.js"></script>
<script src="./js/bootstrap-toggle.min.js"></script>
<script src="./js/bootbox.min.js"></script>
<script src="./js/jquery-confirm.min.js"></script>
<script src="./js/jquery.flot.min.js"></script>
<script src="./js/jquery.flot.time.js"></script>
<script src="./js/jquery.flot.tooltip.js"></script>
</head>
<body>
Main content here
<div id="RFD_curent_1"></div>
</body>
<script src='./js/index.js'></script>
</html>
我的index.js
function initialize_currents(){
var time=(new Date).getTime();
for(var i=0;i<14400;i++){
//data1.push([time+i-14400000,32]);
data1.push([]);
}
for(var i=0;i<14400;i++){
//data2.push([time+i-14400000,25]);
data2.push([]);
}
//data.push([time,0]);
var dataset = [{label: "0xbb36",data: data1},{label:"0xc563",data:data2}];
$.plot($("#RFD_curent_1"), dataset, options);
}
$(document).ready(function() {
initialize_currents();
}
我在Chrome控制台中收到以下警告和错误消息
jquery.min.js:2 jQuery.Deferred exception: Cannot read property 'toLowerCase' of undefined TypeError: Cannot read property 'toLowerCase' of undefined
at Object.t.color.extract
(http://192.168.0.170/js/jquery.flot.min.js:1:695)
at _ (http://192.168.0.170/js/jquery.flot.min.js:1:27080)
at W (http://192.168.0.170/js/jquery.flot.min.js:1:13848)
at new e (http://192.168.0.170/js/jquery.flot.min.js:2:1045)
at Function.t.plot (http://192.168.0.170/js/jquery.flot.min.js:2:3828)
at initialize_currents (http://192.168.0.170/js/index.js:109:11)
at HTMLDocument.<anonymous> (http://192.168.0.170/js/index.js:434:9)
at e (http://192.168.0.170/js/jquery.min.js:2:29453)
at t (http://192.168.0.170/js/jquery.min.js:2:29755) undefined
jquery.min.js:2 Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
at Object.t.color.extract (jquery.flot.min.js:1)
at _ (jquery.flot.min.js:1)
at W (jquery.flot.min.js:1)
at new e (jquery.flot.min.js:2)
at Function.t.plot (jquery.flot.min.js:2)
at initialize_currents (index.js:109)
at HTMLDocument.<anonymous> (index.js:434)
at e (jquery.min.js:2)
at t (jquery.min.js:2)
答案 0 :(得分:0)
所以我知道问题很简单,您用逗号(,)演示了浮点数,应该是点(。)
//data2.push([time+i-14400000.25]);
答案 1 :(得分:0)
Flot期望其数据集中包含两个元素的数组(x值,y值)。您给它一个包含许多空数组的数组。您可能应该使用
之类的东西data2.push([i, i]);
作为测试数据。