score:12
UPDATED
here is how you remove it 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() ;
});
});
remove path by id
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() ;
});
});
score:0
For anyone using polymer or who just wants to do this using pure js, here's how to manage an object that will be created on load and then redrawn every time the chart updates:
http://jsfiddle.net/57xw879k/1/
The advantage of this is that it's added to the chart object, so you're not relying on the DOM or any particular method of accessing it.
http://api.highcharts.com/highcharts/chart.events is also worth a read if you want to perform actions at different times.
HTML:
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container"></div>
<button id="remove">
Remove label
</button>
<button id="add">
Add label
</button>
JS:
const chart = Highcharts.chart('container', {
chart: {
events: {
render: function() {
handleLabel(this)
var label = this.renderer.label('The chart was just redrawn', 100, 120)
.attr({
fill: Highcharts.getOptions().colors[0],
padding: 10,
r: 5,
zIndex: 8
})
.css({
color: '#FFFFFF'
})
.add()
setTimeout(function () {
label.fadeOut()
}, 1000)
}
}
},
title: {text: 'Highcharts label actions'},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
})
function handleLabel(chart) {
if (chart.myLabel) {
chart.myLabel.destroy()
addLabel(chart)
} else {
addLabel(chart)
}
}
function addLabel(chart) {
var point = chart.series[0].points[8];
chart.myLabel = chart.renderer.label('Max observation', 270, 50, 'callout', point.plotX + chart.plotLeft, point.plotY + chart.plotTop)
.css({
color: '#FFFFFF'
})
.attr({
fill: 'rgba(0, 0, 0, 0.75)',
padding: 8,
r: 5,
zIndex: 6
})
.add()
}
function removeLabel(chart) {
!objectIsEmpty(chart.myLabel) && chart.myLabel && chart.myLabel.destroy()
}
function objectIsEmpty(obj) {
return Object.keys(obj).length === 0 && obj.constructor === Object
}
document.getElementById('remove').addEventListener('click', () => removeLabel(chart))
document.getElementById('add').addEventListener('click', () => addLabel(chart))
score:1
I have found that element.remove()
works fine in Chrome, but not when running in a WebView
on Android, for example, and may therefore not work in other browser environments.
Delving through the object's properties and methods, I found a safeRemoveChild()
method, which seems to work even in a WebView
. So that's something along the lines of:
var path = chart.renderer.path(['M', 1200, 10, 'V', 1500, 0])
.attr({
'stroke-width': 2,
stroke: 'red'
})
.add();
// remove the path
path.safeRemoveChild(path.element);
score:15
For future Googlers, this will work:
var path = chart.renderer.path(['M', 1200, 10, 'V', 1500, 0])
.attr({
'stroke-width': 2,
stroke: 'red'
})
.add();
// remove the path
path.element.remove();
Source: stackoverflow.com
Related Query
- Highcharts remove renderer path
- Set color of highcharts renderer path title
- How to remove button from Highcharts
- Proper way to remove all series data from a highcharts chart?
- Remove shadow/background glow on highcharts data label?
- Highcharts remove zero value labels
- remove series by name or id in highcharts
- How can I remove the white border from HighCharts pie chart?
- Highcharts - remove times between dates on a datetime xaxis type
- HighCharts remove stack totals
- Extend highcharts renderer symbols to have plus sign
- Highcharts how to remove headers from tooltip
- Highcharts - How to remove connecting line between fixed tooltip and point
- Remove space between yAxis and data in highcharts
- Animate stroke-width with Highcharts renderer
- Remove Highcharts dataLabel border
- Highcharts Column chart with drilldown, remove hyperlink like formatting from x-axis labels
- Highcharts - How to remove tooltip arrows
- Highcharts remove zoom feature
- Highcharts - How can I remove starting and ending padding from area chart
- Highcharts - how to remove "Open in Highcharts Cloud" from the export menu
- Cannot remove all "series" in highcharts
- Highcharts remove gap between start of xAxis and first value
- remove tooltip space between border and content highcharts
- How do I remove the color swatch from my HighCharts legend without affecting the column?
- Remove UTC date from Highcharts tooltip
- Highcharts Remove Space across the x-Axis
- Using PhantomJS to create HighCharts grahps server side for use in PDF creation (PHP) - results in exit code 11 from PHPs exec();
- How to remove the halo/glow around a marker upon hovering a series in Highcharts
- How to remove text which was added via chart.renderer in Highcharts
More Query from same tag
- Highcharts- show all the days of the particular month
- Highcharts two datetime xAxis chart with same ticks interval
- XY trajectory plot using Highcharts
- how to enable drawing multiple lines on highstock basic-line graph?
- one chart, multiple series multiple data with single data
- Not able to render/retain graph on button click HighChart
- Highcharts plotband label zIndex
- How to fill the Area between two series with multiples yAxis in HighChart?
- Highcharts highstocks - candlestick graph has last value partially cut
- How to add ellipsis for highchart titles and subtitles when title has long name
- Highcharts Grouped Data In Subgroup
- Reverse highmaps legend values or color OR draw legend color from other attribute instead of value in series
- How to change the color of series(grouped column chart) only with json object(without js function) on Highchart?
- Dynamic column based highcharts feeding data with jquery and php
- top yAxis overlaps the bottom one
- HighMaps: Change state name on tooltip with various sets of data
- Highcharts tips ? How can I add a class or an id to an Hichcharts DOM component?
- Highcharts zIndex of dataLabel vs renderer.rect vs tooltip
- Can't get category labels to display
- Getting value from tooltip when hover on svg element on the graph created with highcharts
- Highcharts: Is it possible to have a single series exist in multiple stacks in a grouping
- How can I avoid moving flags when mouseovered - highcharts
- highchart's line chart with constant series not plotting when using linear gradient colour
- Stacked column chart with irregular date time interval
- Highcharts Columnrange Questions (multiple y-axes and column widths)
- Additional serires label in highcharts columnrange
- Spline chart series not getting printed on export as image
- Highcharts: how to use setData to add series
- High Charts - Set Solid Gauge Value from JSON
- Do we have undo option in high charts?