2014-01-12 20 views
2

我使用graphaeljs庫中顯示圖表,在ASP.NET MVC 4graphaeljs錯誤

我從graphaeljs網站

<script src="scripts/raphael.js"></script> 
      <script src="scripts/g.raphael-min.js"></script> 
      <script src="scripts/g.bar-min.js"></script> 
      <script> 
       window.onload = function() { 
        var r = Raphael("holder"), 
         fin = function() { 
          this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this); 
         }, 
         fout = function() { 
          this.flag.animate({ opacity: 0 }, 300, function() { this.remove(); }); 
         }, 
         fin2 = function() { 
          var y = [], res = []; 
          for (var i = this.bars.length; i--;) { 
           y.push(this.bars[i].y); 
           res.push(this.bars[i].value || "0"); 
          } 
          this.flag = r.popup(this.bars[0].x, Math.min.apply(Math, y), res.join(", ")).insertBefore(this); 
         }, 
         fout2 = function() { 
          this.flag.animate({ opacity: 0 }, 300, function() { this.remove(); }); 
         }, 
         txtattr = { font: "12px sans-serif" }; 

        r.text(160, 10, "Single Series Chart").attr(txtattr); 
        r.text(480, 10, "Multiline Series Stacked Chart").attr(txtattr); 
        r.text(160, 250, "Multiple Series Chart").attr(txtattr); 
        r.text(480, 250, "Multiline Series Stacked Chart\nColumn Hover").attr(txtattr); 

        r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]]).hover(fin, fout); 
        r.hbarchart(330, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55]], { stacked: true }).hover(fin, fout); 
        r.hbarchart(10, 250, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55]]).hover(fin, fout); 
        var c = r.barchart(330, 250, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55]], { stacked: true, type: "soft" }).hoverColumn(fin2, fout2); 
       }; 
      </script> 

複製該代碼但是,當我在瀏覽器中運行,此消息出現

Uncaught TypeError: Cannot read property 'x' of undefined raphael.js:11 
c._engine.create raphael.js:11 
c raphael.js:9 
window.onload (index):92 

我不知道我做錯了什麼,我完全按照原樣使用這些庫。你能告訴我,我的錯誤可能是什麼?

回答

2

對不起,我沒有看到您發佈的代碼有任何問題。 我爲你做了一個fiddle

這對raphael.js文件顯然是一個問題。

一定要在您的身體標籤上包含class="raphael",並且id="holder"需要包含一個div。

如果失敗,請嘗試重新下載raphael.js

+0

非常感謝。我忘記了ID =「持有人」。被選爲最佳答案。順便說一句,你熟悉graphael,你能幫我一下嗎? http://stackoverflow.com/questions/21097540/weird-chart-maximum-axis-x-value或與http://stackoverflow.com/questions/21098797/where-does-graphael-line-chart-calculates-its最大值?我昨天在這堆...並沒有人回答我 –

+0

對不起,但我實際上並不熟悉raphael/graphael,但我會在任何調查結果上添加評論。 – haferje

+0

非常感謝朋友:) –