EDIT****
I want help with writing the two functions "plotSingleCoverage" and plotAllCoverage below. The major problem I have is that I don't know how to search through all existing datasets on the page and then write out a single array in a dataset, or all array's of the same sort in different datasets. So if anyone could push me in the right direction I would be more than happy =)
Flot Examples
<div id="placeholder" style="width:600px;height:300px;"></div>
<p id="choices">Show:</p>
<a href="javascript:plotSingleCoverage('Test1')">Show coverage of first test</a>
<a href="javascript:plotAllCoverage()">Show coverage of all tests</a>
<script type="text/javascript">
$(function () {
var Test1 = {
"date": {
label: "Date",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"time": {
label: "Time",
data: [[1, 209], [2, 201], [3, 201], [4, 134]]
},
"modules": {
label: "Modules",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"cases": {
label: "Cases",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"failed": {
label: "Failed",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"cover": {
label: "Cover",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
}
};
var Test2 = {
"date": {
label: "Date",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"time": {
label: "Time",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"modules": {
label: "Modules",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"cases": {
label: "Cases",
data: [[1, 101], [2, 201], [3, 201], [4, 45]]
},
"failed": {
label: "Failed",
data: [[1, 301], [2, 454], [3, 43], [4, 125]]
},
"cover": {
label: "Cover",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
}
};
var Test3 = {
"date": {
label: "Date",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"time": {
label: "Time",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"modules": {
label: "Modules",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"cases": {
label: "Cases",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"failed": {
label: "Failed",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"cover": {
label: "errover",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
}
};
/*Need help to write this function, it shall go to that dataset that its argument is, for example in this case it shall go to Test1 and read that cover and plot it in the #placeholder*
function plotSingleCoverage(coverageToPlot){
$.plot($("#placeholder"), [???]);
}
/*This function shall simply go through all avaible datasets and plot all cover array's*/
function plotAllCoverage(){
$.plot($("#placeholder"), [???]);
}
});
</script>
</body>
</html>
Thanks in advance =)开发者_如何学Go
You have a few variables that you can't access in a convenient way. How about holding them in an array so you can loop on them easily and search for the right dataset to take actions on? (from my comment above)
You can make an array of the available data sets like this: var datasets = new Array();
.
Then, when defining a new dataset, do datasets[] = { ...... }
instead of every var Test1 = { ... };
.
var datasets = new Array();
datasets[0] = {
"date": {
label: "Date",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"time": {
label: "Time",
data: [[1, 209], [2, 201], [3, 201], [4, 134]]
},
"modules": {
label: "Modules",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"cases": {
label: "Cases",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"failed": {
label: "Failed",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"cover": {
label: "Cover",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
}
};
datasets[1] = {
"date": {
label: "Date",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"time": {
label: "Time",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"modules": {
label: "Modules",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
},
"cases": {
label: "Cases",
data: [[1, 101], [2, 201], [3, 201], [4, 45]]
},
"failed": {
label: "Failed",
data: [[1, 301], [2, 454], [3, 43], [4, 125]]
},
"cover": {
label: "Cover",
data: [[1, 201], [2, 201], [3, 201], [4, 125]]
}
};
Then, you could access the datasets like this:
alert(datasets[1]);
// datasets[0] holds the first test data, datasets[1] the second, and so on...
$.plot($("#placeholder"), datasets[0]);
Your plotSingleCoverage can then be:
function plotSingleCoverage(dateset){
$.plot($("#placeholder"), dataset);
}
And you can use it like this:
plotSingleCoverage(datasets[0]);
精彩评论