Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6003063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:04:06+00:00 2026-05-23T01:04:06+00:00

This script below is printing out the checkboxes but isn’t plotting anything in the

  • 0

This script below is printing out the checkboxes but isn’t plotting anything in the graph window.

if (key && allDataSets[key])
                data.push(allDataSets[key]); 

    <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>
 </head>
    <body>
    <h1>Flot Examples</h1>

    <div id="placeholder" style="width:600px;height:300px;"></div>

    <p>Here is an example with real data: military budgets for
        various countries in constant (2005) million US dollars (source: <a href="http://www.sipri.org/">SIPRI</a>).</p>

    <p>Since all data is available client-side, it's pretty easy to
       make the plot interactive. Try turning countries on/off with the
       checkboxes below.</p>

    <p id="choices">Show:</p>

<script type="text/javascript">
$(function () {


    var Test1 = {
    "date": {
        label: "Date",
        data: [[1, 20110122], [2, 20110123], [3, 20110124], [4, 20110125]]
    },        
    "time": {
        label: "Time",
          data: [[1, 22.12], [2, 22.12], [3, 22.12], [4, 22.12]]
    },
   "modules": {
        label: "Modules",
         data: [[1, 22], [2, 22], [3, 22], [4, 22]]
    }, 
    "cases": {
        label: "Cases",
         data: [[1, 1312], [2, 1312], [3, 1312], [4, 1312]]
    }, 
    "failed": {
        label: "Failed",
          data: [[1, 75], [2, 77], [3, 64], [4, 55]]
    }, 
    "cover": {
        label: "Cover",
data: [[1, 13.55 ], [2, 23.55], [3, 33.55], [4, 43.55]]
    }}; 

var Test2 = {
    "date": {
        label: "Date",
        data: [[1, 20110122], [2, 20110123], [3, 20110124], [4, 20110125]]
    },        
    "time": {
        label: "Time",
          data: [[1, 22.12], [2, 22.12], [3, 22.12], [4, 22.12]]
    },
   "modules": {
        label: "Modules",
         data: [[1, 22], [2, 22], [3, 22], [4, 22]]
    }, 
    "cases": {
        label: "Cases",
         data: [[1, 1312], [2, 1312], [3, 1312], [4, 1312]]
    }, 
    "failed": {
        label: "Failed",
          data: [[1, 75], [2, 77], [3, 64], [4, 55]]
    }, 
    "cover": {
        label: "Cover",
data: [[1, 13.55 ], [2, 23.55], [3, 33.55], [4, 43.55]]
    }}; 

var Test3 = {
    "date": {
        label: "Date",
        data: [[1, 20110122], [2, 20110123], [3, 20110124], [4, 20110125]]
    },        
    "time": {
        label: "Time",
          data: [[1, 22.12], [2, 22.12], [3, 22.12], [4, 22.12]]
    },
   "modules": {
        label: "Modules",
         data: [[1, 22], [2, 22], [3, 22], [4, 22]]
    }, 
    "cases": {
        label: "Cases",
         data: [[1, 1312], [2, 1312], [3, 1312], [4, 1312]]
    }, 
    "failed": {
        label: "Failed",
          data: [[1, 75], [2, 77], [3, 64], [4, 55]]
    }, 
    "cover": {
        label: "errover",
data: [[1, 13.55 ], [2, 23.55], [3, 33.55], [4, 43.55]]
    }};
       var allDataSets = [Test1,Test2,Test3];

    // hard-code color indices to prevent them from shifting as
    // countries are turned on/off
    for(j=0; j<allDataSets.length; j++){//Going through all datasets, are there any other more simple way to do this???
    var i = 0;
    $.each(allDataSets[j], function(key, val) {
        val.color = i;
        ++i;
    });


    // insert checkboxes 
    var choiceContainer = $("#choices");
    $.each(allDataSets[j], function(key, val) {
        choiceContainer.append('<br/><input type="checkbox" name="' + key +
                               '" checked="checked" id="id' + key + '">' +
                                   '<label for="id' + key + '">'
                                    + val.label + '</label>');
        });


/**************************Here the script stops working???**********************/


        choiceContainer.find("input").click(plotAccordingToChoices);


    function plotAccordingToChoices() {
        var data = [];

        choiceContainer.find("input:checked").each(function () {
            var key = $(this).attr("name");
            if (key && allDataSets[j][key])
                data.push(allDataSets[j][key]);
        });

        if (data.length > 0)
            $.plot($("#placeholder"), data, {
                yaxis: { min: 0 },
                xaxis: { tickDecimals: 0 }
            });
    }

    plotAccordingToChoices();
    }
});

</script>

 </body>
</html>

/***********EDIT****************/
OK so I solved the first issue with was simply replacing allDataSets[key] with allDataSets[j][key]

But as i now uncheck a checkbox I get the following error line 134 allDataSets[…] is null or not an object. Why do I get this error? In other words its this line that is incorrect when I uncheck a checkbox if (key && allDataSets[j][key])

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:04:07+00:00Added an answer on May 23, 2026 at 1:04 am

    Three things you need to do:

    1. Declare that loop variable “j” with the var keyword.

      for(var j=0; j<allDataSets.length; j++) {
      
    2. All that code after your comment line – the click handler etc – needs to move out of that loop.

    3. Inside the click handler, the code needs to iterate over “allDataSets” and then look for the key in each one:

      choiceContainer.find("input:checked").each(function() {
          var key = $(this).attr("name");
          $.each(allDataSets, function(_, set) {
              if (set[key]) data.push(set[key]);
          });
      });
      

    Here is the jsfiddle demonstrating the changes. You’ll note that it looks terrible. That’s because your “allDataSets” re-uses the same keys for each clump. I have no idea what you’re trying to achieve, but those changes will at least make something show up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this script below for loading a hidden div, inside another: $(document).ready(function(){ $(function()
I am using this Ajax script below to make cross domain Ajax calls which
This script works fine on single click but on double click it shows both
I have little problem with printing data like this, I have written script like
This script below works on a field by field basis, and removes the quotes
Sorry, if this to verbose, but I have a perl script that is partly
I have this script below, where I want to download a pdf from a
I have this script below which i found on SO to generate pagination and
I am using this script below and it works well except that it is
I am using this script below, which works. The only thing is it sends

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.