我假设您已经能够让示例 NVD3 Pie Chart 正常工作。
据我所知,唯一的方法是编辑 pieChart.js。从 here 拉取 NVD3 源,在 / src / models / 下打开 pieChart.js 并添加编辑:
tooltip = function(key, y, e, graph) {
return '<h3>' + key + '</h3>' +
'<p>' + y + ' % </p>'
}
或者这里是一个 NVD3 托管链接到 pieChart.js ,编辑 line 19 看起来像这样 '<p>' + y + '</p>'
确保在您的 html 页面中添加脚本,以便在加载 nvd3.js 时覆盖继承的 pieChart 设置
<script src="your/path/to/pieChart.js" type="application/javascript"></script>
更新:
您知道,您传递到图表中的数据将按原样呈现,您将进行百分比计算并将其传递到图表中。饼图切片大小将根据您发送到图表中的数据进行计算。只是让你知道,不管你是否已经知道。
更新日期:2013 年 7 月 30 日
我只是偶然发现了编辑工具提示的正确方法,而无需修改 pieChart.js 文件。
var chart = nv.models.pieChart().x(function(d) {
return d.key;
}).y(function(d) {
return d.daily[0].sales;
}).showLabels(true).values(function(d) {
return d;
}).color(d3.scale.aColors().range()).donut(true).tooltips(true).tooltip(function(key, x, y, e, graph) {
return '<h3>' + key + ' Custom Text Here ' + x + '</h3> here' + '<p> or here ,' + y + '</p>'
});
只是想让你更新答案。所以现在你知道了两种方法。
希望对你有帮助。