【问题标题】:Plotly.deleteTraces using trace's attribute namePlotly.deleteTraces 使用跟踪的属性名称
【发布时间】:2021-08-25 17:58:21
【问题描述】:

我正在尝试通过 JSON 数组的属性来使用 Plotly.deleteTraces。 在这种情况下,我想删除属性 meta = "center"

的痕迹

数据:

[  
 1: {line: {…}, marker: {…}, meta: "center", mode: "lines+markers", name: "TOP", …}
    2: {line: {…}, marker: {…}, meta: "center", mode: "lines+markers", name: "TOP", …}
    3: {line: {…}, marker: {…}, meta: "center", mode: "lines+markers", name: "TOP", …}
    4: {line: {…}, marker: {…}, meta: "center", mode: "lines+markers", name: "TOP", …}]

我在下面尝试过,但它不起作用。请帮忙

function remove_trace(name) {
    let indices = []
    
    Plotly.deleteTraces(plot_main.data.meta = 'center', indices)
}

【问题讨论】:

    标签: plotly plotly.js


    【解决方案1】:

    这可能是您回答的最简单的解决方案。

    name = 'center'
    
        function remove_trace(name) {
            let indices = []
            let traces_to_delete = plot_main.data
    
            $.each(traces_to_delete, function (idx, trace) {
                if (traces_to_delete[idx]['meta'] == name) {
    
                    indices.push(idx)
    
                }
    
            })
    
            Plotly.deleteTraces(plot_main, indices)
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多