为GRaphael条形图添加标签会引发paper.labelise错误

时间:2013-08-30 10:31:57

标签: label bar-chart graphael

我正在尝试使用标签来实现简单的条形图。我正在使用barchart的github graphael示例。

当我尝试将标签功能添加到下面的代码中时,我收到以下错误。在Github上似乎也有open issue

TypeError: paper.labelise is not a function

错误指出的行号是g.bar.js中的第344行。

有人为此错误找到了解决方法吗?我正在使用Raphaël2.0.2和g.Raphael 0.51。

该行号作为g.bar.js的一部分的代码是: -

var label = paper.labelise(multi ? labels[j] && labels[j][i] : labels[i], multi ? values[j][i] : values[i], total);

抛出此错误的示例代码为: -

<!--<!doctype html>-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Static Bar Charts</title>
  <link rel="stylesheet" href="css/demo.css" type="text/css" media="screen" charset="utf-8">
  <link rel="stylesheet" href="css/demo-print.css" type="text/css" media="print" charset="utf-8">
  <script src="https://raw.github.com/DmitryBaranovskiy/g.raphael/master/raphael-min.js" type="text/javascript" charset="utf-8"></script>
  <script src="https://raw.github.com/DmitryBaranovskiy/g.raphael/master/g.raphael.js" type="text/javascript" charset="utf-8"></script>
  <script src="https://raw.github.com/DmitryBaranovskiy/g.raphael/master/g.bar.js" type="text/javascript" charset="utf-8"></script>
  <script type="text/javascript" charset="utf-8">
      window.onload = function () {
          var r = Raphael("holder"),
                  data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
                  data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
                  data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
                  txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };

          r.text(160, 10, "Single Series Chart").attr(txtattr);
//          r.text(480, 10, "Multiline Series Chart").attr(txtattr);
//          r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
//          r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
          var labels = ["Company X", "Company Y", "Company Z"]
          var barChart = r.barchart(10, 10, 300, 220, [[9,5,2]], 0, {stacked: true, type: "soft"}) .label([labels]);
          //r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"}).label([['C', 'D', 'E', 'G', 'L', 'M', 'P', 'S1']]);
          //barChart.label(['a','b','c']);
//          r.barchart(330, 10, 300, 220, data1);
//          r.barchart(10, 250, 300, 220, data2, {stacked: true});
//          r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
      };
  </script>
</head>
<body class="raphael" id="g.raphael.dmitry.baranovskiy.com">
<div id="holder"></div>
<p>
  Demo of <a href="http://g.raphaeljs.com/">G Raphael</a> JavaScript library.
</p>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

我知道它已经晚了,但这是Google搜索同一问题时的第三个结果。 我如何解决这个问题是将此文件用于g.bar.js

https://raw.githubusercontent.com/jhurt/g.raphael/master/g.bar.js

然后我就是:

barChart.label([['label1','label2']], true);