Stock chart with custom GUI
(async () => { function addPopupEvents(chart) { const closePopupButtons = document.getElementsByClassName( 'highcharts-close-popup' ); // Close popup button: Highcharts.addEvent( closePopupButtons[0], 'click', function () { this.parentNode.style.display = 'none'; } ); Highcharts.addEvent( closePopupButtons[1], 'click', function () { this.parentNode.style.display = 'none'; } ); // Add an indicator from popup Highcharts.addEvent( document.querySelectorAll('.highcharts-popup-indicators button')[0], 'click', function () { const typeSelect = document.querySelectorAll( '.highcharts-popup-indicators select' )[0], type = typeSelect.options[typeSelect.selectedIndex].value, period = document.querySelectorAll( '.highcharts-popup-indicators input' )[0].value || 14; chart.addSeries({ linkedTo: 'aapl-ohlc', type: type, params: { period: parseInt(period, 10) } }); chart.stockToolbar.indicatorsPopupContainer.style.display = 'none'; } ); // Update an annotation from popup Highcharts.addEvent( document.querySelectorAll( '.highcharts-popup-annotations ' + 'button' )[0], 'click', function () { const strokeWidth = parseInt( document.querySelectorAll( '.highcharts-popup-annotations ' + 'input[name="stroke-width"]' )[0].value, 10 ), strokeColor = document.querySelectorAll( '.highcharts-popup-annotations input[name="stroke"]' )[0].value; // Stock/advanced annotations have common options under // typeOptions if (chart.currentAnnotation.options.typeOptions) { chart.currentAnnotation.update({ typeOptions: { lineColor: strokeColor, lineWidth: strokeWidth, line: { strokeWidth: strokeWidth, stroke: strokeColor }, background: { strokeWidth: strokeWidth, stroke: strokeColor }, innerBackground: { strokeWidth: strokeWidth, stroke: strokeColor }, outerBackground: { strokeWidth: strokeWidth, stroke: strokeColor }, connector: { strokeWidth: strokeWidth, stroke: strokeColor } } }); } else { // Basic annotations: chart.currentAnnotation.update({ shapes: [{ 'stroke-width': strokeWidth, stroke: strokeColor }], labels: [{ borderWidth: strokeWidth, borderColor: strokeColor }] }); } chart.stockToolbar.annotationsPopupContainer.style.display = 'none'; } ); } // Load the dataset const data = await fetch( 'https://demo-live-data.highcharts.com/aapl-ohlcv.json' ).then(response => response.json()); // split the data set into ohlc and volume const ohlc = [], volume = [], dataLength = data.length; for (let i = 0; i < dataLength; i += 1) { ohlc.push([ data[i][0], // the date data[i][1], // open data[i][2], // high data[i][3], // low data[i][4] // close ]); volume.push([ data[i][0], // the date data[i][5] // the volume ]); } Highcharts.stockChart('container', { chart: { events: { load: function () { addPopupEvents(this); } } }, rangeSelector: { selected: 2 }, yAxis: [{ labels: { align: 'left' }, height: '80%', resize: { enabled: true } }, { labels: { align: 'left' }, top: '80%', height: '20%', offset: 0 }], navigationBindings: { events: { selectButton: function (event) { let newClassName = event.button.className + ' ' + 'highcharts-active'; const topButton = event.button.parentNode.parentNode; if (topButton.classList.contains('right')) { newClassName += ' right'; } // If this is a button with sub buttons, // change main icon to the current one: if (!topButton.classList.contains( 'highcharts-menu-wrapper' )) { topButton.className = newClassName; } // Store info about active button: this.chart.activeButton = event.button; }, deselectButton: function (event) { event.button.parentNode.parentNode.classList.remove( 'highcharts-active' ); // Remove info about active button: this.chart.activeButton = null; }, showPopup: function (event) { if (!this.indicatorsPopupContainer) { this.indicatorsPopupContainer = document .getElementsByClassName( 'highcharts-popup-indicators' )[0]; } if (!this.annotationsPopupContainer) { this.annotationsPopupContainer = document .getElementsByClassName( 'highcharts-popup-annotations' )[0]; } if (event.formType === 'indicators') { this.indicatorsPopupContainer.style.display = 'block'; } else if (event.formType === 'annotation-toolbar') { // If user is still adding an annotation, don't show // popup: if (!this.chart.activeButton) { this.chart.currentAnnotation = event.annotation; this.annotationsPopupContainer.style.display = 'block'; } } }, closePopup: function () { this.indicatorsPopupContainer.style.display = 'none'; this.annotationsPopupContainer.style.display = 'none'; } } }, stockTools: { gui: { enabled: false } }, series: [{ type: 'candlestick', id: 'aapl-ohlc', name: 'AAPL Stock Price', data: ohlc }, { type: 'column', id: 'aapl-volume', name: 'AAPL Volume', data: volume, yAxis: 1 }], responsive: { rules: [{ condition: { maxWidth: 800 }, chartOptions: { rangeSelector: { inputEnabled: false } } }] } }); })();
StockVarious features
Install with NPM
The official Highcharts NPM package comes with support for CommonJS and contains Highcharts, and its Stock, Maps and Gantt packages.
npm install highcharts --save
See more installation optionsDownload our library
The zip archive contains Javascript files and examples. Unzip the zip package and open index.html in your browser to see the examples.
DownloadBuy a license
You can download and try out all Highcharts products for free. Once your project/product is ready for launch, purchase a commercial license.
See License Pricing