score:7
you are creating the chart with an empty series, hence the error. when this line of you code runs it's initializing the highchart immediately, before the series
option has been set.
var chart = createcharttemplate();
i've had better experience with highcharts when i build the series array first, then add it to the options of the constructor in the last step.
specific to your example, the usdeur.js
file already includes an initialized array of data. you simply need to pass it along in the options array. your jsfiddle can be simplified to this.
$(function() {
var chart = new highcharts.stockchart({
chart: {
renderto: 'container'
},
series: [{
name: 'new series',
data: usdeur
}]
});
});
score:0
i have found that you can use the following code in the dynamically called function to get round the highstock option.series[0] = null problem
options.series= [{data:[]}];
// you can now add the dynamic data, eg
options.series[0].data.push([time, val]);
score:0
i achieved adding time series dynamically as follows:
the html part, nothing fancy is here:
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<div id="container" style="height: 400px; min-width: 310px"></div>
and javascript part:
$(function () {
var chart = highcharts.chart('container', {
chart: {
type: 'line'
},
title: {
text: ''
},
subtitle: {
text: ''
},
yaxis: {
title: {
text: 'values'
}
},
plotoptions: {
line: {
datalabels: {
enabled: true
},
enablemousetracking: true
}
},
series: [{
name: 'a',
color: "#ea825f",
data: []
//
},{
name: 'b',
color: "#2a82ff",
data: []
// data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}]
});
var data1 = [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6];
var data2 = [4.0, 11.9, 6.5, 12.5, 11.4, 15.5, 29.2, 24.5, 21.3, 15.3, 14.9, 8.6]
function add_timeseries(data, chart, series_index) {
$.map(data, function(i){
chart.series[series_index].addpoint(i, true, false)
})
}
add_timeseries(data1, chart, 0)
add_timeseries(data2, chart, 1)
});
add_timeseries()
function does the actual job, it fills the time series slot with given data
score:0
you can create the template first and add the series later. but once you have added at least one series, you cannot remove the highcharts-navigator-series
(auto-generated) from a highstock chart. if you want to remove all the series, you can use below code:
while (chart.series.length > 0) {
if (chart.series[0].options.id == 'highcharts-navigator-series') {
break;
}
chart.series[0].remove(true);
}
this will remove all the series except the navigator series. you can then safely add new series to your chart.
score:2
i found one workaround. my use case was to plot values over time, so first value that i was adding to the chart was a pair of valid time stamp with a null
for data:
series : [{
name : 'random data',
data : (function() {
var data = [], time = (new date()).gettime();
data.push([time, null]);
return data;
})()
}]
then whenever new values had to be plotted just added them simply as:
var value = rawdata['my data set']
var plot = [new date().gettime(), value]
mychart.series[0].addpoint(plot, true, false)
this can be tested here, just replace the original definition of the series
with the one from here.
score:2
from the highstock api reference on addseries:
in a stockchart with the navigator enabled, the base series can't be added dynamically.
that is to say, if you're using the navigator, you have to start with at least one series. according to the same api reference, the navigator displays by default.
Source: stackoverflow.com
Related Query
- Adding a series dynamically with HighCharts Stock Charts
- highcharts dynamically adding series with addSeries
- highcharts with dynamically adding multiple series from JavaScript array name value pair
- Highcharts shared tooltip between charts with multiple series and shared tooltip
- Highcharts synchronize tooltip on multiple charts with multiple series
- Charts using Highcharts with multiple series from JSON
- Highcharts with multiple series from JSON Dynamically
- Highcharts - Adding tooltip to ONLY certain dynamically added series
- Adding series dynamically to highcharts using python 3
- Highcharts drilldown to pie chart - Clicking on axis label with multiple series causes pie charts to overlap
- I want to update my series dynamically on highcharts with a click & also bring it to the original way by clicking on an other button (#previous)
- Highcharts series visibility with csv data source
- Adding series dynamically in highcharts
- How to have multiple highcharts with different series data in vuejs without repeating code
- High charts Issue with stock bar chart multiple line series
- Why code of Horizonal line(y-axis) on a single in Highcharts get applied to all other charts integrated with Webdatarocks
- dynamically adding series to highcharts
- Update two series on the same graph dynamically with HighCharts
- How to dynamically addEvent to Highcharts series with multiple charts?
- highcharts column : add dynamically series with drilldown data
- Adding HighCharts Data Series With Property Names
- How to dynamically populate Highcharts column chart with two series
- addpoint is not adding point in highcharts ,where data is updated dynamically with ajax
- Dynamically added Highcharts series with min and max
- Issue with tooltip on Highcharts with multiple series added dynamically
- Changing data dynamically for a series in Highcharts
- Changing series color in highcharts dynamically
- Highcharts doesn't display series with lots of data points
- Highcharts data series issue with ajax/json and PHP
- adding series to highcharts from JSON
More Query from same tag
- Selecting a data entry on load event causes empty fill
- Inner Margin on Highcharts Graph
- Highcharts with dual axis and stacking - R
- Draw vertical lines and horizontal bands
- Area charts in Highcharts: min and minPadding for y-axis
- Highcharts (SVG) text in Times New Roman for phantomjs but everything else in Helvetica
- How to aggregate boolean values in elastic search?
- Setup of Highcharts and PhantomJS on Windows 7. JSON string parse error
- How to create arrays for Highchart?
- Adding information to xAxis - r shiny
- Highcharts Gauge: Labels radius styling
- Reverse one chart and leave the other unreversed - Synchronized highcharts
- how to show one more array in the tooltip using highchart?
- Highcharts - top justify instead of center entire chart
- Highcharts Sankey customization
- HighCharts event on column category name click
- Can color of data label be different inside and outside of the bar in Highchart, even if it has negative numbers?
- Angular 9 Highcharts - when using series of type pie with type gauge the innerSize of pie is not working
- Remove arrow that hide/show stock tools GUI
- Change the background color above a curve
- How to detect the correct date format in highcharts
- Dynamic chart using Highcharts with data from MySQL database
- Pie chart slice - center of mass
- Highcharts solid gauge not coloured entirely
- HighCharts Graphs don't load half the time
- Always show "0" value in Stacked Column Chart
- Highcharts : draw a chart with data from XMLHttpRequest ()
- Add/Remove Highstock stock tools?
- Highcharts update chart scroll issue- scroll to initial position
- Highcharts - Drag ColumRange