我如何添加一些文本到NVD3离散条形图的工具提示

How can I add some text to the tooltip of NVD3 discreteBarChart?

本文关键字:NVD3 条形图 工具提示 文本 何添加 添加      更新时间:2023-09-26

我试图添加一些文本到我的nvd3离散条形图的工具提示,但它不起作用,我不知道为什么。当我在工具提示上方时,它总是显示以下内容:[object Object] undefined cal。你有什么好主意吗?

historicalBarChart = [
            {
                key: "Notenvergabe",
                values: [
                    {
                        "label" : "1" ,
                        "value" : <?php echo $sel_an_datas["note_1"]; ?>
                    } ,
                    {
                        "label" : "1,3" ,
                        "value" : <?php echo $sel_an_datas["note_2"]; ?>
                    }
                ]
            }
        ];

        nv.addGraph(function() {
            var chart = nv.models.discreteBarChart()
                .x(function(d) { return d.label })
                .y(function(d) { return d.value })
                .staggerLabels(false)
                .showValues(true)
                .duration(250);
                chart.height(250)
                chart.tooltipContent(function(key, y, e, graph) {
                    var x = String(key);
                    var y =  String(y);
                    tooltip_str = '<center><b>'+x+'</b></center>' + y;
                    return tooltip_str;
                });

            d3.select('#chart1 svg')
                .datum(historicalBarChart)
                .call(chart);
            nv.utils.windowResize(chart.update);
            return chart;
        });

显然是这样做的:

tooltipContent(function(key, y, e, graph) { return 'Some String' })
参考