2

我正在尝试在视图中包含图表,但它不起作用。有人可以帮忙吗?

这就是我的观点(flotr2.min.js 在 public/javascripts 中):

...
<div id="container">
   <!--[if lt IE 9]>
   <script type="text/javascript" src="/static/lib/FlashCanvas/bin/flashcanvas.js">     </script>
   <![endif]-->
   <%= javascript_include_tag "flotr2.min.js" %>
   <script type="text/javascript">

   (function () {
      var d1 = [
        [1, 10], [2, 8], [3, 5],[4, 13]],
    d2 = [[1,12],[2,12],[3,12],[4,12],[5, 12]]

   graph = Flotr.draw(container, [{data: d1, label: "Test"}, {data: d2, lines:{show: true}, points: {show: true}}], {
mode: 'time',
    xaxis: {
    ticks: [[1, "Jan"],[2, "Feb"], [3, "Mrz"], [4, "Apr"], [5, "Mai"], [6, "Jun"],
                [7, "Jul"],[8, "Aug"], [9, "Sep"], [10, "Okt"], [11, "Nov"], [12, "Dez"]]     

    },
    grid: {
        minorVerticalLines: true,
    backgroundColor: 'white'
     }
  });
 })();
 </script>

</div>
4

2 回答 2

1

您可能需要修复您的容器大小,请尝试在您的脑海中使用这种样式:

<style type="text/css">
  #container {
    width : 600px;
    height: 384px;
    margin: 8px auto;
  }
</style>

我还发现 github 上的当前版本不起作用。试试www.humblesoftware.com/static/js/flotr2.min.js

于 2012-02-23T22:18:31.190 回答
0

您的脚本中缺少容器变量。在头部包含 flotr2.min.js。容器必须具有正宽度:

<div id="container" style="height: 420px; width: 100%;"></div>

试试这样:

 <script type="text/javascript">
    var container = document.getElementById('container'),
    d1 = [[1, 10], [2, 8], [3, 5],[4, 13]], 
    d2 = [[1,12],[2,12],[3,12],[4,12],[5, 12]];

       Flotr.draw(container, [{data: d1, label: "Test"}, {data: d2, lines:{show: true}, points: {show: true}}],
     {mode: 'time',
        xaxis: {
        ticks: [[1, "Jan"],[2, "Feb"], [3, "Mrz"], [4, "Apr"], [5, "Mai"], [6, "Jun"],
                    [7, "Jul"],[8, "Aug"], [9, "Sep"], [10, "Okt"], [11, "Nov"], [12, "Dez"]]     
        },
        grid: {
            minorVerticalLines: true,
        backgroundColor: 'white'
         }
      });
    </script>
于 2013-01-14T10:40:04.573 回答