How to Display a Blank Graph with Flot


Just as the title states, I'm looking to display a blank "template" graph (by which, I mean that the webpage will display a graph without any lines on it) for a finance calculator that I'm building for work. The basic setup of the webpage will have a blank graph at the top with an HTML form below to accept data entry. Once the user inputs the data and clicks submit, the graph should populate with that data.

Two questions arise from this. First, is it even possible? Second, if it is possible, what would I pass into the $.plot() function? Here is what I'm working with so far:

<div id="main-content">
    <div id="chart" style="width:600px;height:300px;"></div>
    <script type="text/javascript">
        $(document).ready(function() {
            $.plot($("#chart"), [[null]]);
        });
    </script>
</div>

Any advice would be greatly appreciated! Thank you!

EDIT: I forgot to mention this. When I go to view this webpage, Firebug gives me this error message:

uncaught exception: Invalid dimensions for plot, width = 928, height = 0

EDIT FOR ANSWER: It seems that the error message was coming from me using the width and height attributes of the div, instead of styling them with width and height. After fixing that, it works! All code displayed here now works properly.


Answers:


Just ditch the null. If you want an empty "box" pass no data arrays:

$(document).ready(function() {
  $.plot($("#chart"), []);
});

If you want a "plot" with no data, pass an empty data array:

$(document).ready(function() {
  $.plot($("#chart"), [[]]);
});

enter image description here


Running code:

<!DOCTYPE html>
<html>

<head>
  <script data-require="jquery@3.0.0" data-semver="3.0.0" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js"></script>
  <script data-require="flot@0.8.2" data-semver="0.8.2" src="//cdnjs.cloudflare.com/ajax/libs/flot/0.8.2/jquery.flot.min.js"></script>
</head>

<body>
  <div id="chart" style="width:200px; height:200px"></div>
  <script>
    $(document).ready(function() {
      $.plot($("#chart"), [
        []
      ]);
    });
  </script>
</body>

</html>