如何在rails中包含flotr2图表



我试图在视图中包含一个图表,但它不起作用。有人能帮忙吗?

这就是我在视图中看到的(flotr2.min.js在public/javascript中):

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

您可能需要调整容器大小,请尝试在脑海中使用以下样式:

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

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

脚本中缺少容器变量。在头中包含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>

相关内容

  • 没有找到相关文章

最新更新