最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to Display a Blank Graph with Flot - Stack Overflow

programmeradmin0浏览0评论

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 ing 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.

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 ing 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.

Share Improve this question edited Jan 3, 2012 at 17:50 Z. Charles Dziura asked Jan 3, 2012 at 17:16 Z. Charles DziuraZ. Charles Dziura 9334 gold badges18 silver badges41 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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"), [[]]);
});


Running code:

<!DOCTYPE html>
<html>

<head>
  <script data-require="[email protected]" data-semver="3.0.0" src="https://cdnjs.cloudflare./ajax/libs/jquery/3.0.0/jquery.js"></script>
  <script data-require="[email protected]" data-semver="0.8.2" src="//cdnjs.cloudflare./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>

发布评论

评论列表(0)

  1. 暂无评论