Javascript django-nvd3 chart.tooltipContent不是函数

Javascript django-nvd3 chart.tooltipContent不是函数,javascript,python,django,nvd3.js,Javascript,Python,Django,Nvd3.js,我试图在这里使用饼图示例,并且我已经在教程中包含了js库,但是该图表不会被渲染,并且会显示以下js错误 TypeError: chart.tooltipContent is not a function <anonymous> test:23 a.render/c() TypeError:chart.tooltipContent不是函数 测试:23 a、 渲染/c() HTML输出:` <head> <link media="all" href="/s

我试图在这里使用饼图示例,并且我已经在教程中包含了js库,但是该图表不会被渲染,并且会显示以下js错误

TypeError: chart.tooltipContent is not a function
<anonymous>
 test:23
a.render/c()
TypeError:chart.tooltipContent不是函数
测试:23
a、 渲染/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>

数据图表容器=[{“值”:[{“值”:52,“标签”:“苹果”},{“值”:48,“标签”:“杏子”},{“值”:160,“标签”:“鳄梨”},{“值”:94,“标签”:“香蕉”},{“值”:75,“标签”:“博森浆果”},{“值”:71,“标签”:“蓝莓”},{“值”:490,“标签”:“日期”},{“值”:82,“标签”:“葡萄柚:“Kiwi”},{“value”:17,“label”:“Lemon”}],“key”:“serie1”}];
nv.addGraph(函数(){
var chart=nv.models.pieChart();
页边空白({顶部:30,右侧:60,底部:20,左侧:60});
var datum=数据\图表\容器[0]。值;
图表.颜色(d3.比例.类别20().范围());
图表工具内容(函数(键、y、e、图形){
var x=字符串(键);
var y=字符串(graph.point.y);
工具提示\u str=''+x+''+y;
返回工具提示\u str;
});
图表.显示标签(正确);
图.油炸圈饼(假);
图表。显示图例(正确);
图表
.x(函数(d){返回d.label})
.y(函数(d){返回d.value});
图表.高度(450);
d3.选择(“#piechart_容器svg”)
.基准(基准)
.transition().持续时间(500)
.attr('height',450)
.电话(图表);
});
特瑞
`
昨天,当我试图在没有django nvd的情况下使用nvd3 js库时,遇到了这样的错误,无论如何,这是我最后一次尝试使用这个库



更新:我曾尝试使用github的repo中提供的demo django项目,但同样的错误仍然存在

tooltipContent
被弃用,并且
tooltip
被移动到它自己的对象中


使用,并传入一个构建内容的函数

我刚刚解决了这个问题。因为django-nvd3调用python-nvd3(也是由同一个人开发的python nvd3的包装器)的函数和模板


liquidpele的答案完全正确。只需将python-nvd3模板文件中的所有函数
chart.tooltipContent
替换为
chart.tooltip.contentGenerator
(更新调用该函数的文件)。此词典可能会出现在python库的安装位置,就像/lib/python2.7/sites-packages一样

总结卡坎的答案,也要具体一点。您需要通过在python站点包的“nvd3”模块的相应行上将“chart.tooltipContent”替换为“chart.tooltip.contentGenerator”来编辑这些文件

1.)第54行和第63行的pythonx.x/site-packages/nvd3/templates/content.html

2.)第18行的pythonx.x/site-packages/nvd3/templates/piechart.html



然后只需刷新或硬刷新浏览器,图表就会出现

,直到开发人员合并,您可能希望更新您的requirements.txt以包含以下行:


-egit://github.com/aniketmaithani/python-nvd3#egg=python-nvd3

代码是在nvd3 django模块中生成的,我将尝试研究如何修复此问题……您能进一步解释一下吗?比如你要替换哪个文件,从哪个文件夹和哪一行?非常感谢,它工作得很好