Highcharts删除渲染器路径

pet*_*ski 10 jquery highcharts

以下是它的添加方式:

chart.renderer.path(['M', 1200, 10, 'V', 1500, 0])
            .attr({
                'stroke-width': 2,
                stroke: 'red'
            })
            .add();
Run Code Online (Sandbox Code Playgroud)

但是如何删除呢?

var x = someValue;
chart.renderer.path(['M', x, 10, 'V', 1500, 0])
        .attr({
            'stroke-width': 2,
            stroke: 'red'
        })
        .add();
Run Code Online (Sandbox Code Playgroud)

Irv*_*ing 14

对于未来的Google员工,这将有效:

var path = chart.renderer.path(['M', 1200, 10, 'V', 1500, 0])
.attr({
    'stroke-width': 2,
    stroke: 'red'
})
.add();

// remove the path
path.element.remove();
Run Code Online (Sandbox Code Playgroud)


Min*_*iel 12

更新

这是你如何删除它jsFiddle

  function(chart) { // on complete

    chart.renderer.path(['M', 0, 0, 'L', 100, 100, 200, 50, 300, 100])
        .attr({
            'stroke-width': 2,
            stroke: 'red'
        })
        .add();
    $(":button").click(function(){
        $('path[d="M 0 0 L 100 100 200 50 300 100"]').remove() ;
         });
    });
Run Code Online (Sandbox Code Playgroud)

按ID删除路径

的jsfiddle

    function(chart) { // on complete

    chart.renderer.path(['M', 0, 0, 'L', 100, 100, 200, 50, 300, 100])
        .attr({
            'stroke-width': 2,
            stroke: 'red' ,
            id :'myPath'
        })
        .add();
    $(":button").click(function(){
        $("#myPath").remove() ;
                                        });
     });
Run Code Online (Sandbox Code Playgroud)