{"id":13306,"date":"2021-09-07T05:31:27","date_gmt":"2021-09-07T05:31:27","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=13306"},"modified":"2023-07-29T13:09:08","modified_gmt":"2023-07-29T13:09:08","slug":"ohlc-chart-javascript","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/","title":{"rendered":"How to Create Financial Open-High-Low-Close (OHLC) Chart Using JavaScript"},"content":{"rendered":"<p><a href=\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/\"><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart.png\" alt=\"Interactive Open-High-Low-Close (OHLC) chart built with JavaScript on a laptop screen\" width=\"100%\" class=\"alignnone size-full wp-image-13395\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart.png 1500w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart-300x169.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart-768x432.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart-1024x576.png 1024w\" sizes=\"(max-width: 1500px) 100vw, 1500px\" \/><\/a><span style=\"font-size: large;\"><strong><em>A stepwise guide on how to create interactive financial charts in the form of an OHLC chart. Visualizing the stock prices of Amazon over the course of Jeff Bezos&#8217;s tenure as the CEO.<\/em><\/strong><\/span><\/p>\n<p>Financial charts are especially useful to represent large amounts of data and identify trends. Would like to learn one such cool financial chart called the OHLC chart that visualizes stock price movement?<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2>What is an OHLC chart and what does it represent?<\/h2>\n<p>An <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/ohlc-chart\/\">OHLC chart<\/a> shows the open, high, low, and closing prices of a stock. It is a type of bar chart that is used to illustrate movements in the price of a financial instrument over time. A vertical line indicates the high and low prices while small horizontal lines on that vertical line show the open (left line) and close (right line) figures. The colour of the line indicates whether the closing price of the instrument was more or less than the opening price.<\/p>\n<p>Here, I have decided to plot the highs and lows of Amazon Inc. on the Nasdaq under the leadership of Jeff Bezos. Amazon has grown tremendously, and the stock price has seen a lot of ups and downs through the years.<\/p>\n<p>Take a look at my final OHLC chart here and hope that makes you excited to learn how to create this chart:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/s3.gifyu.com\/images\/ohlc-chart-js-preview-1.gif\" width=\"100%\" alt=\"Animated preview demonstration of the final JavaScript OHLC chart created in the tutorial\" \/><\/p>\n<h2>Creating the OHLC chart with JavaScript<\/h2>\n<p>Using any JavaScript library makes it faster and easier to create visualizations with their ready to use chart options. There are a lot of good <a href=\"https:\/\/en.wikipedia.org\/wiki\/Comparison_of_JavaScript_charting_libraries\" target=\"_blank\" rel=\"nofollow\">JavaScript charting libraries<\/a> that can be used to make beautiful charts though not all of them may have stock charts. For this tutorial, I am using the <a href=\"https:\/\/www.anychart.com\/\">AnyChart JS library<\/a> which has some cool financial charts under the <a href=\"https:\/\/www.anychart.com\/products\/anystock\/overview\/\">AnyStock<\/a> umbrella.<\/p>\n<p>A working knowledge of HTML and JavaScript makes it easier to grasp the concepts but don\u2019t worry in case you are a total newbie too. I will show you how you can create an interactive, useful JS OHLC chart in 4 basic steps. It\u2019s time to start the session!<\/p>\n<h3>1. Create an HTML page<\/h3>\n<p>To start with, I create an HTML page to hold the chart and add a block element with a unique id that I will reference later.<\/p>\n<p>I set the <code>&lt;div&gt;<\/code> to have 100% width and height which will display the OHLC chart over the whole screen. You can change these parameters to suit your requirements.<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Word Tree Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; height: 100%; margin: 0; padding: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \r\n\u00a0\u00a0\u00a0\u00a0&lt;\/style&gt;\r\n\u00a0\u00a0&lt;\/head&gt;\r\n\u00a0\u00a0&lt;body&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>2. Include the necessary scripts<\/h3>\n<p>When using a charting library, I need to include the appropriate JS scripts of that library in the HTML page.<\/p>\n<p>To create an OHLC chart, I will link the AnyChart\u2019s \u2018<a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#core\" target=\"_blank\" rel=\"nofollow\">core<\/a>\u2019 and \u2018<a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#stock\" target=\"_blank\" rel=\"nofollow\">stock<\/a>\u2019 modules.<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n&nbsp;&nbsp;&lt;head&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;JavaScript OHLC Chart&lt;\/title&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.10.0\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.10.0\/js\/anychart-stock.min.js\"&gt;&lt;\/script&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;style type=\"text\/css\"&gt;      \r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;html, body, #container { \r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width: 100%; height: 100%; margin: 0; padding: 0; \r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} \r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/style&gt;\r\n&nbsp;&nbsp;&lt;\/head&gt;\r\n&nbsp;&nbsp;&lt;body&gt;  \r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;script&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ All the code for the JS OHLC chart will come here\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/script&gt;\r\n&nbsp;&nbsp;&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>3. Add the data<\/h3>\n<p>To load the data file, I need to add the <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#data_adapter\" target=\"_blank\" rel=\"nofollow\">Data Adapter module<\/a> of AnyChart and do so in the <code>&lt;head&gt;<\/code> section of the HTML page.<\/p>\n<p>For the stock chart, I take the data from <a href=\"https:\/\/finance.yahoo.com\/quote\/AMZN\/history?p=AMZN\" target=\"_blank\" rel=\"nofollow\">Yahoo finance<\/a>. I am using weekly stock price data for Amazon from the time it was listed on the Nasdaq to the last week of June. You can download the data file <a href=\"https:\/\/gist.githubusercontent.com\/shacheeswadia\/e2fd68f19e5331f87d38473a45a11dbe\/raw\/396b3e14f2d7e05aa188e0a420a7b622ed4111bd\/amzohlcweekly.csv\" target=\"_blank\" rel=\"nofollow\">here<\/a>.<\/p>\n<pre><code class=\"html\">&lt;script&gt;\r\n&nbsp;&nbsp;anychart.onDocumentReady(function () {\r\n&nbsp;&nbsp;&nbsp;&nbsp;anychart.data.loadCsvFile('https:\/\/gist.githubusercontent.com\/shacheeswadia\/e2fd68f19e5331f87d38473a45a11dbe\/raw\/396b3e14f2d7e05aa188e0a420a7b622ed4111bd\/amzohlcweekly.csv', function (data) {\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ All code here\r\n&nbsp;&nbsp;&nbsp;&nbsp;})\r\n&nbsp;&nbsp;});\r\n&lt;\/script&gt;<\/code><\/pre>\n<h3>4. Write the JavaScript code for the chart<\/h3>\n<p>Now that everything else is done, let\u2019s jump into writing the code to create and show the OHLC chart.<\/p>\n<p>The first thing I do is enclose the code inside a function called <code>anychart.onDocumentReady()<\/code>. This is to make sure that the code will be executed only after the page is fully loaded. Then, I load the data with the <code>anychart.data.loadJsonFile()<\/code> function.<\/p>\n<p>To use the data, I create a dataset table and then map the values to indicate that my data is in the sequence of open, high, low, and close data points.<\/p>\n<pre><code class=\"javascript\">\/\/ create data table on loaded data\r\nvar dataTable = anychart.data.table();\r\ndataTable.addData(data);\r\n\r\n\/\/ map loaded data for the ohlc series\r\nvar mapping = dataTable.mapAs({\r\n  open: 1,\r\n  high: 2,\r\n  low: 3,\r\n  close: 4\r\n});<\/code><\/pre>\n<p>Next, I create the stock chart and plot it. Then, I map the data to the plot and define the grid settings. In a stock chart, it is always a good idea to keep the grid to facilitate easier reading of the chart figures.<\/p>\n<pre><code class=\"javascript\">\/\/ create stock chart\r\nvar chart = anychart.stock();\r\n\r\n\/\/ create first plot on the chart\r\nvar plot = chart.plot(0);\r\n\r\n\/\/ create ohlc series\r\nplot\r\n  .ohlc()\r\n  .data(mapping)\r\n  .name('AMZ');\r\n\r\n\/\/ set grid settings\r\nplot\r\n  .yGrid(true)\r\n  .xGrid(true)\r\n  .yMinorGrid(true)\r\n  .xMinorGrid(true);<\/code><\/pre>\n<p>I add a scroller series under the main chart to allow a closer look at any specified range of data.<\/p>\n<p>Lastly, I add the title of the chart, reference the chart container and draw the chart.<\/p>\n<pre><code class=\"javascript\">\/\/ create scroller series with mapped data\r\nchart.scroller().area(dataTable.mapAs({ value: 4 }));\r\n\r\n\/\/ sets the title of the chart\r\nchart.title('Amazon Inc. Stock Prices');\r\n\r\n\/\/ set container id for the chart\r\nchart.container('container');\r\n\r\n\/\/ initiate chart drawing\r\nchart.draw();<\/code><\/pre>\n<p>That\u2019s all there is to do! A functional, interactive OHLC chart is conjured up!<\/p>\n<p>It can be quite clearly seen that the stock prices have risen steadily with major gains after 2012 and a sharp rise in 2020.<\/p>\n<p><iframe sandbox=\"allow-scripts allow-pointer-lock allow-same-origin\n                 allow-popups allow-modals allow-forms\" frameBorder=\"0\" class=\"anychart-embed anychart-embed-UnIRxPVh\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/UnIRxPVh\/iframe\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-UnIRxPVh{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>You can see that the legend is automatically added and on hovering, useful crosshair lines with the tooltip are displayed.<\/p>\n<p>This is the power of the JavaScript library where a seemingly complex stock chart is created with such few steps. You can check out the entire code of the initial version here or on <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/wvJVZXz\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a> [or on <a href=\"https:\/\/playground.anychart.com\/UnIRxPVh\/\" target=\"_blank\" rel=\"nofollow\">Playground<\/a>].<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n&nbsp;&nbsp;&lt;head&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;JavaScript OHLC Chart&lt;\/title&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.10.0\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.10.0\/js\/anychart-stock.min.js\"&gt;&lt;\/script&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;style type=\"text\/css\"&gt;      \r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;html, body, #container { \r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width: 100%; height: 100%; margin: 0; padding: 0; \r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} \r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/style&gt;\r\n&nbsp;&nbsp;&lt;\/head&gt;\r\n&nbsp;&nbsp;&lt;body&gt;  \r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;script&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;anychart.onDocumentReady(function () {\r\nanychart.data.loadCsvFile('https:\/\/gist.githubusercontent.com\/shacheeswadia\/e2fd68f19e5331f87d38473a45a11dbe\/raw\/396b3e14f2d7e05aa188e0a420a7b622ed4111bd\/amzohlcweekly.csv', function (data) {\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ create data table on loaded data\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var dataTable = anychart.data.table();\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dataTable.addData(data);\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ map loaded data for the ohlc series\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var mapping = dataTable.mapAs({\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;open: 1,\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;high: 2,\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;low: 3,\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;close: 4\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ create stock chart\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var chart = anychart.stock();\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ create first plot on the chart\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var plot = chart.plot(0);\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ create ohlc series\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;plot\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.ohlc()\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.data(mapping)\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.name('AMZ');\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ set grid settings\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;plot\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.yGrid(true)\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.xGrid(true)\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.yMinorGrid(true)\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.xMinorGrid(true);\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ create scroller series with mapped data\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chart.scroller().area(dataTable.mapAs({ value: 4 }));\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ sets the title of the chart\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chart.title('Amazon Inc. Stock Prices');\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ set container id for the chart\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chart.container('container');\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ initiate chart drawing\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chart.draw();\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});\r\n&nbsp;&nbsp;&nbsp;&nbsp;});\r\n&nbsp;&nbsp;&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2>Customizing the JavaScript OHLC chart<\/h2>\n<p>I feel that the basic version of the interactive OHLC chart is pretty awesome as it is. But, to guide you on how JS charting libraries make it convenient to modify the chart according to one\u2019s preference and display some more information, I will showcase a few customizations for this chart.<\/p>\n<h3>1. Add an EMA line<\/h3>\n<p>In a stock chart, technical indicators like moving averages, Bollinger bands, relative strength index, standard deviation and such are often used by analysts to predict price fluctuations.<\/p>\n<p>An important and popular technical indicator is <a href=\"https:\/\/www.investopedia.com\/terms\/e\/ema.asp\" target=\"_blank\" rel=\"nofollow\">Exponential Moving Average<\/a> (EMA) which helps to identify the trend direction by giving more weightage to recent observations. This functionality is inbuilt in the charting library so all I have to do is map the data and a line representing the EMA values is drawn over the chart. See how this indicator automatically shows up in the legend and you can toggle showing or hiding the line by clicking on the legend.<\/p>\n<pre><code class=\"javascript\">\/\/ create EMA indicators with period 50\r\nplot\r\n  .ema(dataTable.mapAs({ value: 4 }));<\/code><\/pre>\n<h3>2. Fix a default chart display range<\/h3>\n<p>Since the chart data ranges from 1997 to 2021, it is quite a long period. If you want to focus on some specific area or show a particular range of dates, you can define the start and end dates. This will render the chart over that date period.<\/p>\n<pre><code class=\"javascript\">\/\/ set chart selected date\/time range\r\nchart.selectRange('2009-07-01', '2021-06-31');<\/code><\/pre>\n<p><iframe sandbox=\"allow-scripts allow-pointer-lock allow-same-origin\n                 allow-popups allow-modals allow-forms\" frameBorder=\"0\" class=\"anychart-embed anychart-embed-qVTLiUdW\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/qVTLiUdW\/iframe\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-qVTLiUdW{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>You can have a look at this version of the OHLC chart on <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/MWpNRPQ\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a> [or on <a href=\"https:\/\/playground.anychart.com\/qVTLiUdW\/\" target=\"_blank\" rel=\"nofollow\">Playground<\/a>].<\/p>\n<h3>3. Change the colour theme<\/h3>\n<p>A simple yet effective way to make your chart look aesthetically personalized is to change the colours of the chart. There are multiple colour themes available in the AnyChart library.<\/p>\n<p>I use a dark theme by including the script for that theme and setting it in the code. I like the lighter colour showing the positive close and the darker red showing the negative close for each data point.<\/p>\n<pre><code class=\"javascript\">&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/v8\/themes\/dark_glamour.min.js\"&gt;&lt;\/script&gt;\r\n\r\n...\r\n\r\n\/\/ set chart theme\r\nanychart.theme('darkGlamour');<\/code><\/pre>\n<h3>4. Modify some aesthetics<\/h3>\n<p>A small change I make in the legend is modifying the icon to indicate the rising or falling of the stock price. And I also change the colour of the EMA line by using the Amazon logo colour.<\/p>\n<pre><code class=\"javascript\">\/\/ create EMA indicators with period 50\r\nplot\r\n  .ema(dataTable.mapAs({ value: 4 }))\r\n  .series()\r\n  .stroke('1 #f79400');<\/code><\/pre>\n<p><iframe sandbox=\"allow-scripts allow-pointer-lock allow-same-origin\n                 allow-popups allow-modals allow-forms\" frameBorder=\"0\" class=\"anychart-embed anychart-embed-i0AJBtJo\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/i0AJBtJo\/iframe\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-i0AJBtJo{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p><a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/NWpQmoj\" target=\"_blank\" rel=\"nofollow\">Here<\/a> is the whole code with these modifications. [Check it out on <a href=\"https:\/\/playground.anychart.com\/i0AJBtJo\/\" target=\"_blank\" rel=\"nofollow\">Playground<\/a>.]<\/p>\n<h3>5. Include specific pre-defined range selection options<\/h3>\n<p>In financial charts, there are certain shorter time periods that are often used by users to check the price movement.<\/p>\n<p>The great part about stock charts in the JS charting library is that all such functionalities are available by default. So again, all I have to do is add the range selector into my code. Just one thing before using this functionality is to include the required script and stylesheets that I add in the <code>&lt;head&gt;<\/code> section. You can click on the buttons to render the chart for that zoom level.<\/p>\n<pre><code class=\"javascript\">\/\/ create range selector\r\nvar rangeSelector = anychart.ui.rangeSelector();\r\n\r\n\/\/ init range selector\r\nrangeSelector.render(chart);<\/code><\/pre>\n<h3>6. Add some events on the chart<\/h3>\n<p>Stock prices can fluctuate based on events or news. So, I decided to showcase some events that include product launches by Amazon and the start of the global pandemic which has made the Amazon stock price rise steeply.<\/p>\n<p>I add the events data and the settings to display the events. This is a great way to make your chart more informative.<\/p>\n<pre><code class=\"javascript\">\/\/ set markers data\r\neventMarkers.data([\r\n&nbsp;&nbsp;{ \"symbol\": 1, date: '1998-04-11', description: '2-for-1 Amazon stock split' },\r\n&nbsp;&nbsp;{ \"symbol\": 2, date: '2000-11-01', description: 'Amazon launches Marketplace' },\r\n&nbsp;&nbsp;{ \"symbol\": 3, date: '2002-07-20', description: 'Amazon launches AWS - Amazon Web Services' },\r\n&nbsp;&nbsp;{ \"symbol\": 4, date: '2005-02-01', description: 'Amazon launches Prime membership' },\r\n&nbsp;&nbsp;{ \"symbol\": 5, date: '2007-11-19', description: 'Amazon released the Kindle, its first e-reader for $399' },\r\n&nbsp;&nbsp;{ \"symbol\": 6, date: '2014-11-15', description: 'Amazon launches Echo, a speaker powered by its digital assistant Alexa' },\r\n&nbsp;&nbsp;{ \"symbol\": 7, date: '2020-03-11', description: 'Covid-19 declared as a global pandemic by WHO' }\r\n]);<\/code><\/pre>\n<p>That\u2019s the closing bell and a lovely, interactive JS OHLC chart is all done! Go ahead and check out the final version of the chart on <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/bGqXJyW\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a> [or on <a href=\"https:\/\/playground.anychart.com\/1u06yBEU\/\" target=\"_blank\" rel=\"nofollow\">Playground<\/a>].<\/p>\n<p><iframe sandbox=\"allow-scripts allow-pointer-lock allow-same-origin\n                 allow-popups allow-modals allow-forms\" frameBorder=\"0\" class=\"anychart-embed anychart-embed-1u06yBEU\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/1u06yBEU\/iframe\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-1u06yBEU{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<h2>Conclusion<\/h2>\n<p>This tutorial was just about one financial chart \u2014 an OHLC chart \u2014 with some features applied. There is a plethora of other series and customization options available so I would suggest that you have a look at what else is possible <a href=\"https:\/\/docs.anychart.com\/Stock_Charts\/Overview\" target=\"_blank\" rel=\"nofollow\">starting from here<\/a>.<\/p>\n<p>Actually, there are many <a href=\"https:\/\/en.wikipedia.org\/wiki\/Comparison_of_JavaScript_charting_libraries\" target=\"_blank\" rel=\"nofollow\">JavaScript charting libraries<\/a> out there that provide many necessary chart types and features out of the box, making interactive data visualization more convenient. Some of them do support financial charts. You can have a closer look and make your own choice based on your specific needs.<\/p>\n<p>It may be difficult to predict markets and stock movements but quite easy to plot them! Do let me know if you have any doubts or need any guidance.<\/p>\n<hr \/>\n<p><strong><em>Published with permission of Shachee Swadia. Originally appeared on <a href=\"https:\/\/dev.to\/shacheeswadia\/creating-a-financial-ohlc-chart-with-javascript-29p8\" target=\"_blank\" rel=\"nofollow\">DEV Community<\/a> under the title &#8220;Creating a Financial OHLC Chart with JavaScript&#8221; on July 29, 2021.<\/em><\/strong><\/p>\n<hr \/>\n<p><strong><em>You are more than welcome to learn more about open-high-low-close charts on <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/ohlc-chart\/\">Chartopedia<\/a> and\u00a0check out other <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JavaScript charting tutorials<\/a> on our blog.<\/em><\/strong><\/p>\n<hr \/>\n<p><strong><em>Do you want to create a cool guest post for our blog?\u00a0<a href=\"https:\/\/www.anychart.com\/support\/\">Let us know<\/a>!<\/em><\/strong><\/p>\n<p><!-- SyntaxHighlighter --><link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/styles\/default.min.css\"><link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/styles\/atom-one-light.min.css\"><script src=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/highlight.min.js\"><\/script><script>hljs.initHighlightingOnLoad();<\/script><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>A stepwise guide on how to create interactive financial charts in the form of an OHLC chart. Visualizing the stock prices of Amazon over the course of Jeff Bezos&#8217;s tenure as the CEO. Financial charts are especially useful to represent large amounts of data and identify trends. Would like to learn one such cool financial [&hellip;]<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,18,263,19,23,13,279,20,4],"tags":[843,1282,2206,2207,2208,53,93,72,73,260,254,1758,284,127,166,258,363,471,266,620,1292,880,806,1759,195,294,2220,2838,54,1389,1760,2757,256,1111,350,842,744,844,130,165,313,1370,743,133,774,775,145,1978,179,2842,47,912,805,1762,913,2013,2014,32,55,144,146,2843,36,907,141,249,81,57,1238,142,96,99,58,65,56,101,911,1937,2335,1938,2387,2388,199,2841,2846,459,200,37,910,920,1958,1959,1960,2844,30,172,954,293,745,899,1939,2015,2816,1763,804],"class_list":["post-13306","post","type-post","status-publish","format-standard","hentry","category-anychart-charting-component","category-anystock","category-big-data","category-financial-charts","category-html5","category-javascript","category-javascript-chart-tutorials","category-stock-charts","category-tips-and-tricks","tag-advanced-data-visualization","tag-air-travel-data-visualization","tag-amazon","tag-amazon-data","tag-amazon-data-visualization","tag-anychart","tag-anystock","tag-area-chart","tag-area-charts","tag-best-data-visualization-examples","tag-chart","tag-chart-design","tag-chart-examples","tag-chart-types","tag-charting","tag-charts","tag-current-price-indicator","tag-data-analysis","tag-data-analytics","tag-data-analytics-examples","tag-data-chart","tag-data-charting","tag-data-charts","tag-data-design","tag-data-over-time","tag-data-science","tag-data-visual","tag-data-visualisation","tag-data-visualization","tag-data-visualization-best-pracices","tag-data-visualization-design","tag-data-visualization-development","tag-data-visualization-examples","tag-data-visualization-practice","tag-data-visualization-projects","tag-data-visualization-task","tag-data-visualization-techniques","tag-data-visualization-tutorial","tag-data-visualization-weekly","tag-data-visualizations","tag-data-visuals","tag-data-viz-examples","tag-data-viz","tag-dataviz","tag-dataviz-examples","tag-dataviz-projects","tag-dataviz-weekly","tag-datetime-charts","tag-design","tag-dev-community","tag-financial-charts","tag-financial-data","tag-front-end-development","tag-guest-post","tag-historical-stock-prices","tag-html","tag-html-charts","tag-html5","tag-html5-charts","tag-infographics","tag-interactive-data-visualization","tag-j","tag-javascript","tag-javascript-chart-tutorial","tag-javascript-charting","tag-javascript-charting-api","tag-javascript-charting-library","tag-javascript-charts","tag-javascript-graph","tag-javascript-graphics","tag-javascript-graphics-library","tag-javascript-library","tag-js-chart","tag-js-charting","tag-js-charts","tag-js-graphics","tag-js-stock-chart","tag-json","tag-json-charts","tag-json-data-visualization","tag-market-data","tag-market-data-visualization","tag-ohlc-chart","tag-open-high-low-close-chart","tag-pric","tag-statistics","tag-stock-chart","tag-stock-charts","tag-stock-data","tag-stock-exchange-data","tag-stock-market","tag-stock-market-data","tag-stock-market-data-visualization","tag-time-series-chart","tag-tips-and-tricks","tag-tutorial","tag-visual-data-analytics","tag-visualization","tag-visualization-techniques","tag-visualizations","tag-visualizing-json-data","tag-web-charts","tag-web-design","tag-web-developers","tag-web-development","wpautop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Creating Financial Open-High-Low-Close (OHLC) Chart with JavaScript<\/title>\n<meta name=\"description\" content=\"A stepwise tutorial on how to easily create interactive financial charts in the form of an OHLC chart. Visualizing Amazon&#039;s stock prices under Jeff Bezos.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Financial OHLC Chart Using JavaScript\" \/>\n<meta property=\"og:description\" content=\"A stepwise tutorial on how to easily build financial charts in the form of an OHLC chart. Visualizing Amazon&#039;s stock prices under Jeff Bezos.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"AnyChart News\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/AnyCharts\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-07T05:31:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-29T13:09:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart-social.png\" \/>\n<meta name=\"author\" content=\"Shachee Swadia\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"How to Create Financial OHLC Chart Using JavaScript\" \/>\n<meta name=\"twitter:description\" content=\"A stepwise tutorial on how to easily build financial charts in the form of an OHLC chart. Visualizing Amazon&#039;s stock prices under Jeff Bezos.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart-social.png\" \/>\n<meta name=\"twitter:creator\" content=\"@AnyChart\" \/>\n<meta name=\"twitter:site\" content=\"@AnyChart\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shachee Swadia\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/\"},\"author\":{\"name\":\"Shachee Swadia\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"headline\":\"How to Create Financial Open-High-Low-Close (OHLC) Chart Using JavaScript\",\"datePublished\":\"2021-09-07T05:31:27+00:00\",\"dateModified\":\"2023-07-29T13:09:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/\"},\"wordCount\":1532,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart.png\",\"keywords\":[\"advanced data visualization\",\"air travel data visualization\",\"Amazon\",\"Amazon data\",\"Amazon data visualization\",\"AnyChart\",\"AnyStock\",\"area chart\",\"area charts\",\"best data visualization examples\",\"chart\",\"chart design\",\"chart examples\",\"chart types\",\"charting\",\"charts\",\"current price indicator\",\"data analysis\",\"data analytics\",\"data analytics examples\",\"data chart\",\"data charting\",\"data charts\",\"data design\",\"data over time\",\"data science\",\"data visual\",\"data visualisation\",\"Data Visualization\",\"data visualization best practices\",\"data visualization design\",\"data visualization development\",\"data visualization examples\",\"data visualization practice\",\"data visualization projects\",\"data visualization task\",\"data visualization techniques\",\"data visualization tutorial\",\"data visualization weekly\",\"data visualizations\",\"data visuals\",\"data viz examples\",\"data-viz\",\"dataviz\",\"dataviz examples\",\"dataviz projects\",\"dataviz weekly\",\"date\/time charts\",\"design\",\"DEV Community\",\"Financial charts\",\"financial data\",\"front-end development\",\"guest post\",\"historical stock prices\",\"HTML\",\"HTML charts\",\"HTML5\",\"html5 charts\",\"infographics\",\"interactive data visualization\",\"j\",\"JavaScript\",\"javascript chart tutorial\",\"javascript charting\",\"javascript charting api\",\"JavaScript charting library\",\"javascript charts\",\"javascript graph\",\"javascript graphics\",\"JavaScript graphics library\",\"JavaScript library\",\"js chart\",\"js charting\",\"js charts\",\"JS graphics\",\"JS stock chart\",\"JSON\",\"JSON charts\",\"JSON data visualization\",\"market data\",\"market data visualization\",\"ohlc chart\",\"open-high-low-close chart\",\"pric\",\"statistics\",\"stock chart\",\"Stock charts\",\"stock data\",\"stock exchange data\",\"stock market\",\"stock market data\",\"stock market data visualization\",\"time-series-chart\",\"Tips and tricks\",\"tutorial\",\"visual data analytics\",\"visualization\",\"visualization techniques\",\"visualizations\",\"visualizing JSON data\",\"web charts\",\"web design\",\"web developers\",\"web development\"],\"articleSection\":[\"AnyChart Charting Component\",\"AnyStock\",\"Big Data\",\"Financial Charts\",\"HTML5\",\"JavaScript\",\"JavaScript Chart Tutorials\",\"Stock Charts\",\"Tips and Tricks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/\",\"name\":\"Creating Financial Open-High-Low-Close (OHLC) Chart with JavaScript\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart.png\",\"datePublished\":\"2021-09-07T05:31:27+00:00\",\"dateModified\":\"2023-07-29T13:09:08+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"description\":\"A stepwise tutorial on how to easily create interactive financial charts in the form of an OHLC chart. Visualizing Amazon's stock prices under Jeff Bezos.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart.png\",\"width\":1500,\"height\":844},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create Financial Open-High-Low-Close (OHLC) Chart Using JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\",\"url\":\"https:\/\/www.anychart.com\/blog\/\",\"name\":\"AnyChart News\",\"description\":\"AnyChart JS Charts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.anychart.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\",\"name\":\"Shachee Swadia\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g\",\"caption\":\"Shachee Swadia\"},\"url\":\"https:\/\/www.anychart.com\/blog\/author\/shachee-swadia\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Creating Financial Open-High-Low-Close (OHLC) Chart with JavaScript","description":"A stepwise tutorial on how to easily create interactive financial charts in the form of an OHLC chart. Visualizing Amazon's stock prices under Jeff Bezos.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Financial OHLC Chart Using JavaScript","og_description":"A stepwise tutorial on how to easily build financial charts in the form of an OHLC chart. Visualizing Amazon's stock prices under Jeff Bezos.","og_url":"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2021-09-07T05:31:27+00:00","article_modified_time":"2023-07-29T13:09:08+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart-social.png","type":"","width":"","height":""}],"author":"Shachee Swadia","twitter_card":"summary_large_image","twitter_title":"How to Create Financial OHLC Chart Using JavaScript","twitter_description":"A stepwise tutorial on how to easily build financial charts in the form of an OHLC chart. Visualizing Amazon's stock prices under Jeff Bezos.","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart-social.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Shachee Swadia","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/"},"author":{"name":"Shachee Swadia","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"headline":"How to Create Financial Open-High-Low-Close (OHLC) Chart Using JavaScript","datePublished":"2021-09-07T05:31:27+00:00","dateModified":"2023-07-29T13:09:08+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/"},"wordCount":1532,"commentCount":0,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart.png","keywords":["advanced data visualization","air travel data visualization","Amazon","Amazon data","Amazon data visualization","AnyChart","AnyStock","area chart","area charts","best data visualization examples","chart","chart design","chart examples","chart types","charting","charts","current price indicator","data analysis","data analytics","data analytics examples","data chart","data charting","data charts","data design","data over time","data science","data visual","data visualisation","Data Visualization","data visualization best practices","data visualization design","data visualization development","data visualization examples","data visualization practice","data visualization projects","data visualization task","data visualization techniques","data visualization tutorial","data visualization weekly","data visualizations","data visuals","data viz examples","data-viz","dataviz","dataviz examples","dataviz projects","dataviz weekly","date\/time charts","design","DEV Community","Financial charts","financial data","front-end development","guest post","historical stock prices","HTML","HTML charts","HTML5","html5 charts","infographics","interactive data visualization","j","JavaScript","javascript chart tutorial","javascript charting","javascript charting api","JavaScript charting library","javascript charts","javascript graph","javascript graphics","JavaScript graphics library","JavaScript library","js chart","js charting","js charts","JS graphics","JS stock chart","JSON","JSON charts","JSON data visualization","market data","market data visualization","ohlc chart","open-high-low-close chart","pric","statistics","stock chart","Stock charts","stock data","stock exchange data","stock market","stock market data","stock market data visualization","time-series-chart","Tips and tricks","tutorial","visual data analytics","visualization","visualization techniques","visualizations","visualizing JSON data","web charts","web design","web developers","web development"],"articleSection":["AnyChart Charting Component","AnyStock","Big Data","Financial Charts","HTML5","JavaScript","JavaScript Chart Tutorials","Stock Charts","Tips and Tricks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/","url":"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/","name":"Creating Financial Open-High-Low-Close (OHLC) Chart with JavaScript","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart.png","datePublished":"2021-09-07T05:31:27+00:00","dateModified":"2023-07-29T13:09:08+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"description":"A stepwise tutorial on how to easily create interactive financial charts in the form of an OHLC chart. Visualizing Amazon's stock prices under Jeff Bezos.","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/08\/open-high-low-close-js-chart.png","width":1500,"height":844},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2021\/09\/07\/ohlc-chart-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create Financial Open-High-Low-Close (OHLC) Chart Using JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.anychart.com\/blog\/#website","url":"https:\/\/www.anychart.com\/blog\/","name":"AnyChart News","description":"AnyChart JS Charts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.anychart.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51","name":"Shachee Swadia","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g","caption":"Shachee Swadia"},"url":"https:\/\/www.anychart.com\/blog\/author\/shachee-swadia\/"}]}},"_links":{"self":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/13306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/comments?post=13306"}],"version-history":[{"count":24,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/13306\/revisions"}],"predecessor-version":[{"id":16198,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/13306\/revisions\/16198"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=13306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=13306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=13306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}