我正在尝试用标签实现一个简单的条形图。我正在使用 graphael 的github barchart示例。
当我尝试将标签函数添加到下面的代码中时,出现以下错误。Github 上似乎也有一个未解决的问题。
TypeError: paper.labelise is not a function
错误指出的行号是 g.bar.js 中的第 344 行。
有人有解决此错误的方法吗?我正在使用 Raphaël 2.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>