Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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)</p> <p>You can make an array of the available data sets like this: <code>var datasets = new Array();</code>. Then, when defining a new dataset, do <code>datasets[] = { ...... }</code> instead of every <code>var Test1 = { ... };</code>.</p> <pre><code>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]] } }; </code></pre> <p>Then, you could access the datasets like this:</p> <pre><code>alert(datasets[1]); // datasets[0] holds the first test data, datasets[1] the second, and so on... $.plot($("#placeholder"), datasets[0]); </code></pre> <p>Your plotSingleCoverage can then be:</p> <pre><code>function plotSingleCoverage(dateset){ $.plot($("#placeholder"), dataset); } </code></pre> <p>And you can use it like this:</p> <pre><code>plotSingleCoverage(datasets[0]); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COThis was very useful, have one more question if you don't mind, your answer give access and plot the data date, time, modules, cases, failed, covered. But if I for instance want to only access the "cover" data in dataset[0], how do I accomplish that? Also say that I want to print out both "cover" in dataset[0] and dataset[1], how can I do that? Thank you so much =)
      singulars
    2. CO@Matt: Since we have the datasets in an `array`, we access them with their index in the array - `datasets[0]`, etc. But each dataset is an object - so we can access it like this: `alert(datasets[0].cover);` and `alert(datasets[0].cover.label);` and so on :) BTW - Objects in JavaScript are basically associative arrays - you can also access the label of the cover of dataset 0 like this: `alert(datasets[0]["cover"]["label"]);`, but the first option is much more clear about the type of this element.
      singulars
    3. COWow thank you, one last question if you don't mind :P I had to change the name on "cover", "failed" to "Test1cover", "Test2cover" and "Test1failed" and "Test2failed" etc. Now if I want to access everything with "cover" in its label name, how can I do this? Like for example do a for loop going through all datasets and look for all labels containing "cover"? (if you wonder there are going to be around 20 diffrent, like datasets[19], so I can't use the alert(datasets[0]["cover"]["label"]); since the label wont be only "cover" anymore?. Thank you so much in advance yet again :D
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload