Javascript 需要关于flot jquery数据集的建议吗
嗨,关于下面的脚本,我有两个问题 问题1:为什么只有Test1date、Test1time、Test1Test1模块等。。。。获取不同的颜色,而Test1date、Test2date、Test3date等的颜色。。。得到相同的颜色,我怎么能改变这个 问题2:我只想打印下面“失败”和“覆盖”的复选框,但如何检查密钥是否包含带有“覆盖”或“失败”的内容??至于现在,我检查一个键是否等于“Test3failed”或“Test2cover”。但我只想检查key==包含“cover”或“failed”的内容 提前感谢=)Javascript 需要关于flot jquery数据集的建议吗,javascript,jquery,html,flot,Javascript,Jquery,Html,Flot,嗨,关于下面的脚本,我有两个问题 问题1:为什么只有Test1date、Test1time、Test1Test1模块等。。。。获取不同的颜色,而Test1date、Test2date、Test3date等的颜色。。。得到相同的颜色,我怎么能改变这个 问题2:我只想打印下面“失败”和“覆盖”的复选框,但如何检查密钥是否包含带有“覆盖”或“失败”的内容??至于现在,我检查一个键是否等于“Test3failed”或“Test2cover”。但我只想检查key==包含“cover”或“failed”的内
弗洛特例子
弗洛特例子
显示:
$(函数(){
变量名称1={
“Test1date”:{
标签:“COSDate”,
数据:[[1201],[2201],[3201],[4125]]
},
“Test1time”:{
标签:“时间”,
数据:[[1209],[2201],[3201],[4134]]
},
“测试1测试1模块”:{
标签:“模块”,
数据:[[1201],[2201],[3201],[4125]]
},
“Test1案例”:{
标签:“箱子”,
数据:[[1201],[2201],[3201],[4125]]
},
“Test1失败”:{
标签:“失败”,
数据:[[1201],[2201],[3201],[4125]]
},
“Test1cover”:{
标签:“封面”,
数据:[[1201],[2201],[3201],[4125]]
}};
变量名称2={
“Test2date”:{
标签:“CASDate”,
数据:[[1201],[2201],[3201],[4125]]
},
“Test2time”:{
标签:“时间”,
数据:[[1201],[2201],[3201],[4125]]
},
“Test2模块”:{
标签:“模块”,
数据:[[1201],[2201],[3201],[4125]]
},
“Test2cases”:{
标签:“箱子”,
数据:[[1101],[2201],[3201],[4201],[4205]]
},
“Test2failed”:{
标签:“失败”,
数据:[[1301],[2454],[3,43],[4125]]
},
“Test2cover”:{
标签:“封面”,
数据:[[1201],[2201],[3201],[4125]]
}};
变量名称3={
“Test3date”:{
标签:“MVSDate”,
数据:[[1201],[2201],[3201],[4125]]
},
“Test3time”:{
标签:“时间”,
数据:[[1201],[2201],[3201],[4125]]
},
“Test3模块”:{
标签:“模块”,
数据:[[1201],[2201],[3201],[4125]]
},
“Test3cases”:{
标签:“箱子”,
数据:[[1201],[2201],[3201],[4125]]
},
“Test3failed”:{
标签:“失败”,
数据:[[1245],[2501],[3432],[4195]]
},
“Test3cover”:{
标签:“errover”,
数据:[[1201],[2201],[3201],[4125]]
}};
var alldataset=[Name1,Name2,Name3];
//硬编码颜色索引,以防止它们随着时间的推移而移动
//国家/地区处于打开/关闭状态
对于(var j=0;j 0)
$.plot($(“#占位符”),数据{
系列:{
行:{show:true},
要点:{show:true}
},
十字线:{mode:“x”},
网格:{hoverable:true,clickable:true},
yaxis:{min:0},
xaxis:{tickDecimals:0}
});
}
绘图依据目录();
});
1)由于设置了var i=0,因此对象的颜色相同
在每个循环的开始处,将其移动到循环表达式的外部
2) 您可以使用.indexOf
检查一个变量是否包含另一个变量。例如,要检查key
是否包含“cover”,可以执行以下操作:if(key.indexOf(“cover”)>-1{…}
1)由于设置了var i=0,因此对象的颜色相同
在每个循环的开始处,将其移动到循环表达式的外部
2) 您可以使用.indexOf
检查一个变量是否包含另一个变量。例如,要检查key
是否包含“cover”,可以执行以下操作:if(key.indexOf(“cover”)>-1{…}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="root/include/excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="root/include/jquery.js"></script>
<script language="javascript" type="text/javascript" src="root/include/jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="root/include/jquery.flot.crosshair.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:400px;"></div>
<p id="choices">Show:</p>
<script type="text/javascript">
$(function () {
var Name1 = {
"Test1date": {
label: "COSDate",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"Test1time": {
label: "Time",
data: [[1, 209], [2, 201], [3, 201], [4, 134]]
},
"Test1Test1modules": {
label: "Modules",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"Test1cases": {
label: "Cases",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"Test1failed": {
label: "Failed",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"Test1cover": {
label: "Cover",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
}};
var Name2 = {
"Test2date": {
label: "CASDate",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"Test2time": {
label: "Time",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"Test2modules": {
label: "Modules",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"Test2cases": {
label: "Cases",
data: [[1, 101], [2, 201], [3, 201], [4, 45]]
},
"Test2failed": {
label: "Failed",
data: [[1, 301], [2, 454], [3, 43], [4, 125]]
},
"Test2cover": {
label: "Cover",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
}};
var Name3 = {
"Test3date": {
label: "MVSDate",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"Test3time": {
label: "Time",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"Test3modules": {
label: "Modules",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"Test3cases": {
label: "Cases",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"Test3failed": {
label: "Failed",
data: [[1, 245], [2, 501], [3, 432], [4, 195]]
},
"Test3cover": {
label: "errover",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
}};
var allDataSets = [Name1,Name2,Name3];
// hard-code color indices to prevent them from shifting as
// countries are turned on/off
for(var j=0; j<allDataSets.length; j++){
var i = 0;
$.each(allDataSets[j], function(key, val) {**//Here is where the colours are set for `diffrent data`**
val.color = i; //The same object of the 3 diffrent datasets are getting the `same color, why, and how can I solve this?`
++i;
});
var choiceContainer = $("#choices");
$.each(allDataSets[j], function(key, val) {
if(key=="Test3failed" || key=="Test2cover"){
choiceContainer.append('<br/><input type="checkbox" name="' + key +
'" checked="checked" id="id' + key + '">' +
'<label for="id' + key + '">'
+ val.label + '</label>');
}
});
}
choiceContainer.find("input").click(plotAccordingToChoices);
function plotAccordingToChoices() {
var data = [];
choiceContainer.find("input:checked").each(function() {
var key = $(this).attr("name");
$.each(allDataSets, function(_, set) {
if (set[key]) data.push(set[key]);
});
});
if (data.length > 0)
$.plot($("#placeholder"), data, {
series: {
lines: { show: true },
points: { show: true }
},
crosshair: { mode: "x" },
grid: { hoverable: true, clickable: true},
yaxis: { min: 0 },
xaxis: { tickDecimals: 0 }
});
}
plotAccordingToChoices();
});
</script>
</body>
</html>