django-nvd3 chart.tooltipContent 不是函数
django-nvd3 chart.tooltipContent is not a function
我尝试在 django-nvd3-doc 中使用饼图示例,并且我已经包含了 js 库以继续教程,但是图表不会被渲染,并且会显示以下 js 错误
TypeError: chart.tooltipContent is not a function
<anonymous>
test:23
a.render/c()
HTML 输出:
`
<head>
<link media="all" href="/static/nvd3/build/nv.d3.min.css" type="text/css" rel="stylesheet" />
<script src="/static/d3/d3.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/nvd3/build/nv.d3.min.js" type="text/javascript" charset="utf-8"></script>
<script>
data_piechart_container=[{"values": [{"value": 52, "label": "Apple"}, {"value": 48, "label": "Apricot"}, {"value": 160, "label": "Avocado"}, {"value": 94, "label": "Banana"}, {"value": 75, "label": "Boysenberries"}, {"value": 71, "label": "Blueberries"}, {"value": 490, "label": "Dates"}, {"value": 82, "label": "Grapefruit"}, {"value": 46, "label": "Kiwi"}, {"value": 17, "label": "Lemon"}], "key": "Serie 1"}];
nv.addGraph(function() {
var chart = nv.models.pieChart();
chart.margin({top: 30, right: 60, bottom: 20, left: 60});
var datum = data_piechart_container[0].values;
chart.color(d3.scale.category20().range());
chart.tooltipContent(function(key, y, e, graph) {
var x = String(key);
var y = String(graph.point.y);
tooltip_str = '<center><b>'+x+'</b></center>' + y;
return tooltip_str;
});
chart.showLabels(true);
chart.donut(false);
chart.showLegend(true);
chart
.x(function(d) { return d.label })
.y(function(d) { return d.value });
chart.height(450);
d3.select('#piechart_container svg')
.datum(datum)
.transition().duration(500)
.attr('height', 450)
.call(chart);
});
</script>
</head>
<body>
<h1>tere</h1>
<div id="piechart_container"><svg style="width:600px;height:400px;"></svg></div>
</body>
`
昨天我在尝试使用没有 django-nvd 的 nvd3 js 库时遇到了这样的错误,无论如何这是我给这个库的最后一击
更新:我已经尝试使用 github 的 repo 中提供的演示 django 项目,但同样的错误仍然存在
tooltipContent
已弃用,tooltip
已移至它自己的对象中。
使用chart.tooltip.contentGenerator()
,并传入构建内容的函数。
我刚刚解决了这个问题。因为django-nvd3调用了python-nvd3的函数和模板(也是同一个人开发的python nvd3的wrapper)。
liquippele的回答完全正确。您只需将 python-nvd3 模板文件中的所有函数 chart.tooltipContent
替换为 chart.tooltip.contentGenerator
(更新调用该函数的文件)。该词典可能会出现在您的 python 库安装位置,就像 /lib/python2.7/sites-packages 一样。
根据 cakan 的回答加起来,也很具体。您需要通过在 python 站点包的 'nvd3' 模块的相应行上将 'chart.tooltipContent' 替换为 'chart.tooltip.contentGenerator' 来编辑这些文件。
1.) pythonx.x/site-packages/nvd3/templates/content.html 在行 '54' 和 '63'
2.) pythonx.x/site-packages/nvd3/templates/piechart.html 在行 '18'
然后只需刷新或硬刷新您的浏览器,图表就会出现
在开发者合并 the pull request with this fix 之前,您可能希望更新您的 requirements.txt 以包含此行:
-e git://github.com/aniketmaithani/python-nvd3#egg=python-nvd3
我尝试在 django-nvd3-doc 中使用饼图示例,并且我已经包含了 js 库以继续教程,但是图表不会被渲染,并且会显示以下 js 错误
TypeError: chart.tooltipContent is not a function
<anonymous>
test:23
a.render/c()
HTML 输出:
`
<head>
<link media="all" href="/static/nvd3/build/nv.d3.min.css" type="text/css" rel="stylesheet" />
<script src="/static/d3/d3.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/nvd3/build/nv.d3.min.js" type="text/javascript" charset="utf-8"></script>
<script>
data_piechart_container=[{"values": [{"value": 52, "label": "Apple"}, {"value": 48, "label": "Apricot"}, {"value": 160, "label": "Avocado"}, {"value": 94, "label": "Banana"}, {"value": 75, "label": "Boysenberries"}, {"value": 71, "label": "Blueberries"}, {"value": 490, "label": "Dates"}, {"value": 82, "label": "Grapefruit"}, {"value": 46, "label": "Kiwi"}, {"value": 17, "label": "Lemon"}], "key": "Serie 1"}];
nv.addGraph(function() {
var chart = nv.models.pieChart();
chart.margin({top: 30, right: 60, bottom: 20, left: 60});
var datum = data_piechart_container[0].values;
chart.color(d3.scale.category20().range());
chart.tooltipContent(function(key, y, e, graph) {
var x = String(key);
var y = String(graph.point.y);
tooltip_str = '<center><b>'+x+'</b></center>' + y;
return tooltip_str;
});
chart.showLabels(true);
chart.donut(false);
chart.showLegend(true);
chart
.x(function(d) { return d.label })
.y(function(d) { return d.value });
chart.height(450);
d3.select('#piechart_container svg')
.datum(datum)
.transition().duration(500)
.attr('height', 450)
.call(chart);
});
</script>
</head>
<body>
<h1>tere</h1>
<div id="piechart_container"><svg style="width:600px;height:400px;"></svg></div>
</body>
`
昨天我在尝试使用没有 django-nvd 的 nvd3 js 库时遇到了这样的错误,无论如何这是我给这个库的最后一击
更新:我已经尝试使用 github 的 repo 中提供的演示 django 项目,但同样的错误仍然存在
tooltipContent
已弃用,tooltip
已移至它自己的对象中。
使用chart.tooltip.contentGenerator()
,并传入构建内容的函数。
我刚刚解决了这个问题。因为django-nvd3调用了python-nvd3的函数和模板(也是同一个人开发的python nvd3的wrapper)。
liquippele的回答完全正确。您只需将 python-nvd3 模板文件中的所有函数 chart.tooltipContent
替换为 chart.tooltip.contentGenerator
(更新调用该函数的文件)。该词典可能会出现在您的 python 库安装位置,就像 /lib/python2.7/sites-packages 一样。
根据 cakan 的回答加起来,也很具体。您需要通过在 python 站点包的 'nvd3' 模块的相应行上将 'chart.tooltipContent' 替换为 'chart.tooltip.contentGenerator' 来编辑这些文件。
1.) pythonx.x/site-packages/nvd3/templates/content.html 在行 '54' 和 '63'
2.) pythonx.x/site-packages/nvd3/templates/piechart.html 在行 '18'
然后只需刷新或硬刷新您的浏览器,图表就会出现
在开发者合并 the pull request with this fix 之前,您可能希望更新您的 requirements.txt 以包含此行:
-e git://github.com/aniketmaithani/python-nvd3#egg=python-nvd3