Using HighStocks.js, I tried to add 2 identical graph on the same html page.

My code look like this:

function createGraph(placeHolderId, uniqueName, series) {
    $(placeHolderId).highcharts(uniqueName, {
            rangeSelector : { selected : 1 },
            series : series
    });
}

And I call it 2 times:

createGraph('#marketdata', 'StockChart', series1);
createGraph('#returns', 'Returns', series1);

Even if series are the same, 'market data' get created then for the second I get the error:

TypeError: Highcharts[constr] is not a constructor
chart = new Highcharts[constr](options, args[1]);

on line 1041 of highstock.src.js.

Why is the second failing ?

有帮助吗?

解决方案

the name of the chart needs to be 'StockChart' which is the type of the chart and not a variable name.

$(placeHolderId).highcharts('StockChart', {
        rangeSelector : { selected : 1 },
        series : series
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top