score:10
you can update the options directly and then update the axis:
var newValue = (chart.xAxis[0].options.plotLines[0].value + 1) % 10;
chart.xAxis[0].options.plotLines[0].value = newValue;
chart.xAxis[0].update();
score:0
Update: The solution below is best suited for Highcharts. During subsequent comments and clarification, I learned the original poster is using Highstock, which does not support the
scatter
plot type. I was not successful in adapting this solution to their code, which was anareaspline
chart using data points updated in real time.
Rather than using a plot line, I'd suggest creating a new series that will serve as your line. That way, you can update the series as needed and it will pick up the native animations that Highcharts provides.
Here's a working example using a basic line chart: http://jsfiddle.net/brightmatrix/ws3e1wns/
Below is the code for the new series, which uses the scatter
type. Note that I've disabled the markers, added a line width, and set showInLegend
and enableMouseTracking
to false
so it won't be seen by your users as a "true" data series.
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]
}, {
// scatter plot line to serve as moveable plot line
type: 'scatter',
data: [[0,10],[11,10]],
lineWidth: 1,
marker: {
enabled: false // hide the markers (to show only the line)
},
showInLegend: false, // hide in legend
enableMouseTracking: false // prevent user from interacting with this line
}]
Whenever you click the button in this fiddle, it will move the new series line up 10 points on the y-axis. To do so, I update both ends of the line:
// button handler
var chart = $('#container').highcharts(),
y = 30;
$('#button').click(function () {
y += 10;
// update both ends of the scatter line
chart.series[1].data[0].update([0,y]);
chart.series[1].data[1].update([11,y]);
});
As you can see, the line animates when it is moved.
I hope this is helpful and useful for you!
score:2
we've all probably seen the following page(s), they dont really contain an answer.
https://www.highcharts.com/docs/chart-concepts/plot-bands-and-plot-lines https://api.highcharts.com/highcharts/xAxis.plotLines
@Aviram had a good solution, but my example contains a lot more data , which causes slow redraws.
Ive found that the update()
call does a redraw/rerender in some cases (source link), which can be very expensive and slow for large plots. i used the following code to update just the plot line, and it seems to update the plot line very quick. The reason i update plotLines
and plotLinesAndBands
, as in some cases when you redraw the lines/axis things need to match.
[chart].xAxis[0].options.plotLines[0].value = newVal;
[chart].xAxis[0].plotLinesAndBands[0].options.value = newVal;
[chart].xAxis[0].plotLinesAndBands[0].render();
The render
function used above is called on redraw anyway (source link), so were not doing anything crazy here!
Source: stackoverflow.com
Related Query
- How to update new plotline values instead of removing and adding new ones in highcharts
- How to use add series and update methods in the high chart wrapper for angular?
- Error while adding and removing plotLine on highcharts
- how to pass the dates to the x-axis in the base line high charts instead of the values
- How to update the colour of minColor and maxColor when data is changed in high charts' solid gauge in ReactJS?
- How to update series values of bar with time interval in High chart?
- How to create a new Highstock chart with new Highchart and not jquery?
- How to change graph colour above and below plotline in Highcharts
- Highcharts - how to properly update series[0].data and yAxis title of a VUMeter?
- How do I reduce the space between title and chart of a High Chart?
- How to set xAxis minimum and maximum values on Highstock?
- Angular Highcharts - How to enable noData options and update it dynamically
- High chart - Column Range Chart with Time range. How to get tooltip as Start and End time
- how to pass values to tooltip which not in x and y axis in highcharts
- AJAX displaying values from two different functions in a single Highcharts chart instead of two different ones
- How to feed series data that has x axis and y axis values in line highcharts?
- How to show open, close, high and low in tooltip when the chart type is 'line' in highstocks?
- How can I automate high charts and graphs using selenium webdriver?
- How can I put custom color in High Charts PIE data | Slice and want to change slice text
- High Charts add variance instead of values
- How to draw a bar chart that one series has both positive and negative values in Highcharts?
- Highcharts. How to update x and y of the dataLabel?
- How do I calculate the total Data values for both and display in Legend
- How to manage y-axis values of high chart
- On HighMaps, how do I show state abbreviations instead of state name on a U.S. map and remove data label from point
- Highchart not adding new series or removing old series
- How to delete and add new contents in html file by python
- How to get chart min and max values after Drag zooming in highChart chart?
- How to show values in Highcharts tooltip other than x and y when data points are too high?
- how to sum up all values with same keys in an object inside an array and get their average
More Query from same tag
- Highcharts navigator mouse over not working
- HighCharts show selected point from chart on Pie Chart
- div tag is not visible on integration with Menubar in HTML
- Format Highcharts y-axis labels
- AngularJS With Highcharts WITHOUT JQuery
- No results in Highcharts with loading from JSON
- Deleting last entered comma on PHP code
- Fetch Values for Chart using JSON for Database driven Chart (highchart.js)
- Slider in Highcharts similar to Google Playground
- Highcharts Tooltip formatting for shared Tooltips
- JSON how to get squared brackets?
- Highcharts chart sometimes appears squashed
- Gradle sync failed. Basic functionality will not work properly
- Highcharts do not hold all the values of stacked columns chart with data time axes
- How to move Y axis on highchart
- Highcharts horizontal bar chart with text inside bars
- React Use Function In Javascript Object
- Highchart the horizontal gradline below the 0 axis
- Highcharts with ajax and json data what am i doing wrong?
- In Highchart, why drilldown data of pie chart is not of same color?
- Highchart, I want to fill between some values(point to point). in areaspline chart
- HighCharts rest zoom fails on xy
- Angular HighChart in tabs width
- highstock display tooltip wrong in iframe
- highchart bar data, borders fit to the data
- Column Labels in Sankey Charts in Highcharts
- Highcharts basic bar graphs. How to remove strokewith from the bars
- Highcharts-Angular not working with Angular Universal
- Highcharts - applying background image to container div
- Angular4 with highcharts can't use world.js