score:1
Accepted answer
To add a new series with a single point on each you just need to call this.addSeries()
, like this:
$(function() {
$('#container').highcharts({
chart: {
type: 'spline',
margin: [70, 50, 60, 80],
events: {
click: function(e) {
this.addSeries({
data: [ [e.xAxis[0].value, e.yAxis[0].value] ]
});
}
}
},
title: {
text: 'User supplied data'
},
subtitle: {
text: 'Click the plot area to add a point. Click a point to remove it.'
},
xAxis: {
gridLineWidth: 1,
minPadding: 0.2,
maxPadding: 0.2,
maxZoom: 60
},
yAxis: {
title: {
text: 'Value'
},
minPadding: 0.2,
maxPadding: 0.2,
maxZoom: 60,
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
plotOptions: {
series: {
lineWidth: 1,
point: {
events: {
'click': function() {
if (this.series.data.length > 1) {
this.remove();
}
}
}
}
}
},
series: [{
data: [
[20, 20],
[80, 80]
]
}]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; max-width: 700px; margin: 0 auto"></div>
score:1
By using addSeries
function like this:
$(function () {
$('#container').highcharts({
chart: {
type: 'spline',
margin: [70, 50, 60, 80],
events: {
click: function (e) {
// find the clicked values and the series
var x = e.xAxis[0].value,
y = e.yAxis[0].value;
this.addSeries({
name: "new serie",
data: [[x, y], [x+10, y-10]]
});
}
}
},
title: {
text: 'User supplied data'
},
subtitle: {
text: 'Click the plot area to add a point. Click a point to remove it.'
},
xAxis: {
gridLineWidth: 1,
minPadding: 0.2,
maxPadding: 0.2,
maxZoom: 60
},
yAxis: {
title: {
text: 'Value'
},
minPadding: 0.2,
maxPadding: 0.2,
maxZoom: 60,
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
plotOptions: {
series: {
lineWidth: 1,
point: {
events: {
'click': function () {
if (this.series.data.length > 1) {
this.remove();
}
}
}
}
}
},
series: [{
data: [[20, 20], [80, 80]]
}]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; max-width: 700px; margin: 0 auto"></div>
score:1
$(function () {
$('#container').highcharts({
chart: {
type: 'spline',
margin: [70, 50, 60, 80],
events: {
click: function (e) {
// find the clicked values and the series
var x = e.xAxis[0].value,
y = e.yAxis[0].value,
series = this.series[0];
// Add it
series.addPoint([x,y]);
}
}
},
title: {
text: 'User supplied data'
},
subtitle: {
text: 'Click the plot area to add a point. Click a point to remove it.'
},
xAxis: {
gridLineWidth: 1,
minPadding: 0.2,
maxPadding: 0.2,
maxZoom: 60
},
yAxis: {
title: {
text: 'Value'
},
minPadding: 0.2,
maxPadding: 0.2,
maxZoom: 60,
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
plotOptions: {
series: {
lineWidth: 1,
point: {
events: {
'click': function () {
if (this.series.data.length > 1) {
this.remove();
}
}
}
}
}
},
series: [{
data: [[20, 20], [80, 80]]
}]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; max-width: 700px; margin: 0 auto"></div>
Source: stackoverflow.com
Related Query
- How to add series after click event in HighCharts
- HighCharts : How to add click event on colorAxis in heatmap
- Highcharts add new data to series after click
- highcharts - add series into graph after click
- Highcharts how to add treemap upon click event on line chart?
- How to manually trigger the afterSetExtremes event from a series click event in HighCharts
- How do I add an event listener to a Highcharts object *AFTER* I've created it
- Highcharts : Chart with drilldown how to obtain click event of drill up button
- highcharts how to catch and insert logic in click reset zoom button event
- In high chart how to add event for label click
- How to pass custom data into Highcharts graph click event
- How to add new points to highcharts after plotting the first 'n' points?
- How to attach click event function in Highcharts
- Highcharts : How do I keep the marker formatting and make the click event fire with a 5K+ point scatter plot?
- How do i add mouse wheel code in Angular2 highcharts in typescript
- How do I attach a click event handler to the whole HighCharts Gauge control?
- How to add multiple series in highcharts synchronously
- How to add different click events on each pie of a pie chart created by highcharts usin jquery
- Dynamically add an event to Highcharts series
- How can I make React Native in Android aware of a click event in a tooltip in a Highcharts chart?
- Highcharts - How can I get the nearest point on click event
- Highcharts : click event not detected after a redraw
- How to add Series data in Highcharts from MVC
- how to add onclick event handler inside highcharts tooltip
- HighCharts how to add live series data set to existing chart
- highcharts group series click event to get all data in catagory
- Shiny: Add new series to Highcharts plot on button click
- How do I catch a click event on a polygon in HighCharts without having the tooltip popping up
- Link two series object in Highcharts and add event
- How to add Highcharts series automatically with a 2D-array?
More Query from same tag
- GeoJSON Not Working with Highmaps
- HighStock Charts not Working over SSL ie https
- Highcharts showing nearest point causes flickering crosshair and strange order
- HighChart is preventing click event on a parent
- Highcharts missing first date label on xAxis
- Highcharts export chart exportSettings with svg file
- Drilldown With Linked Series
- Error in render: "TypeError: Cannot read property 'seriesNames' of undefined"
- Vertical align legends in highcharts with two column
- Adding flags to highcharts (not highstock) dynamically
- how to implement moving average in highchart
- Dynamic updates with highcharts
- How to display different tooltip formats in series of data in High Chart
- How to format yaxis value with millions and billion initial letter in Highcharts?
- Highcharts: how to change text and background colors
- How to modify style properties in an Highcharts tag with Angular?
- Highcharts 4.1.1 adding a severe drop shadow to data labels if you specify a font color
- How to set series-label to false by default and change the color of series label text in highchart
- How to create Stacked and Grouped column graph in an inner drilldown?
- Semi donot chart with highcharts
- Highcharts: how to change line color when hovering a scatterplot series
- How to Export JavaScript Chart to Excel file (HighCharts)
- Highchart stack labels don't show up in IE 8
- Multiple Series in HighStock navigator Angular
- Highcharts : How can i move the tooltip to external DIV?
- highcharts start from hinges base
- How to highlight points of multi series in same X value when mouse moves using highcharts?
- HighCharts SyntaxError: missing ] after element list
- Highstock error: a.ownerDocument is undefined
- How can i use double click in Highcharts and get that data