【问题标题】:Find id from NVD3 Pie Chart从 NVD3 饼图中查找 id
【发布时间】:2014-05-10 17:57:29
【问题描述】:

我正在寻找解决方案来解决我的问题。它参考来自 NVD3.ORG http://nvd3.org/livecode/index.html#codemirrorNav的样本

当我单击一个“删除”按钮时,我尝试查找 _id。我编写了这段代码并对其进行了测试,但无法正常工作。任何人都可以帮忙。

'click #delValues': function(){
        var name = $("#modifyChartName").val();
        var findId = function (name){
            Pie.findOne({label: name});
            return _id;
        };
        Pie.remove({
            _id: findId()
        });
        $("#modifyChartName").val("");
        $("#modifyChartValue").val("");
    }

其实我真的需要在饼图上小鸡,然后获取_id并点击“删除”按钮进行删除。

    nv.addGraph(function() {
  var chart = nv.models.pieChart()
      .x(function(d) { return d.label })
      .y(function(d) { return d.value })
      .showLabels(true);

    d3.select("#chart svg")
        .datum(data)
      .transition().duration(1200)
        .call(chart);

  return chart;
});

【问题讨论】:

    标签: d3.js meteor nvd3.js


    【解决方案1】:

    一个老问题,但我正在尝试做类似的事情,并想出了一个可能在这种情况下有所帮助的解决方案。我想在饼图的相应切片悬停时触发<table>(与饼图分开生成)中某一行的突出显示。我可以通过从tooltipContent 获取pointIndex 来做到这一点(我一直用它来自定义工具提示中显示的内容。

    var chart = nv.models.pieChart()
                .tooltipContent( function (key, y, e, graph) {
                    // Get an index number of the hovered slice
                    var sliceId = e.pointIndex;
                    // Do something with that id (separate from nvd3)
                    $("#completionRate tbody tr:nth-child("+sliceId+")").addClass("info");
                    // Customize the actual tooltip
                    return y.substring(0,y.indexOf(".")) + " Patients<br/>" + key;
                });
    

    我可以想象使用相同的技术来获得一个 id/index,然后您可以使用它来分配给删除函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-13
      • 1970-01-01
      • 2016-06-08
      • 2014-12-15
      • 2015-10-22
      • 1970-01-01
      相关资源
      最近更新 更多