{"id":14418,"date":"2022-02-24T13:37:03","date_gmt":"2022-02-24T13:37:03","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=14418"},"modified":"2022-08-13T11:10:20","modified_gmt":"2022-08-13T11:10:20","slug":"stock-chart-js","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/","title":{"rendered":"Building Stock Chart with JavaScript"},"content":{"rendered":"<p><a href=\"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/\"><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js.png\" alt=\"Building a Stock Chart with JavaScript\" width=\"100%\" class=\"alignnone size-full wp-image-14431\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js.png 1500w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js-300x169.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js-768x432.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js-1024x575.png 1024w\" sizes=\"(max-width: 1500px) 100vw, 1500px\" \/><\/a><a href=\"https:\/\/www.anychart.com\/blog\/2018\/11\/20\/data-visualization-definition-history-examples\/\">Data visualization<\/a> is vastly applied in various fields. One such domain is financial trading, where <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/stock-chart\/\">stock charts<\/a> are essential for smart market data analysis and decision making. Whether you invest in stocks or not, I am pretty sure that you have come across such graphics or even might need to build one right now. So, would you like to know how to make a stock chart? I\u2019m ready to show you an easy path using the Tesla stock price data and JavaScript! Come along with me throughout this tutorial and you\u2019ll learn how to quickly create elegant, interactive JS stock charts like the one you see in the picture.<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2>What Is a Stock Chart?<\/h2>\n<p>Most of you may know the basics, but to ensure that we are all on the same page, I will briefly tell you what a stock chart is.<\/p>\n<p>A stock chart basically represents the price or volume movements of a stock over time by plotting the price or volume figures over the Y-axis and the time period over the X-axis.<\/p>\n<p>Stock charts play a very important role in helping investors spot trends and make the right buy and sell decisions in the fast-paced financial markets.<\/p>\n<p>The most common chart type used to depict stocks is the candlestick stock chart. But you can also use open-high-low-close (OHLC), line, area, column, or other forms of series visualization depending on a particular case and task.<\/p>\n<h2>Stock Chart to Be Created<\/h2>\n<p>Tesla is a company that is always in the news. It has grown exponentially over the years and that is pretty much reflected in its stock value over time. So, I am going to build a stock chart to showcase the price movement of Tesla Inc. for this tutorial. I will also show you how to add various technical indicators and illustrate the effect of the recent hype surrounding the selling of stocks by Elon Musk.<\/p>\n<p>Here is a peek at the final version of the JavaScript stock chart to get you all pumped up for the upcoming steps.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js-preview.png\" alt=\"Stock chart\" width=\"100%\" class=\"alignnone size-full wp-image-14433\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js-preview.png 1114w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js-preview-300x174.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js-preview-768x446.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js-preview-1024x595.png 1024w\" sizes=\"(max-width: 1114px) 100vw, 1114px\" \/><\/p>\n<h2>Building a Stock Chart with JavaScript<\/h2>\n<p>Creating an interactive stock chart from scratch can be quite a daunting task but becomes much easier and faster with an appropriate data visualization tool. For example, there are some useful <a href=\"https:\/\/en.wikipedia.org\/wiki\/Comparison_of_JavaScript_charting_libraries\" target=\"_blank\" rel=\"nofollow\">JavaScript charting libraries<\/a> that have the capability to create financial graphics, and you can work with whichever suits your needs.<\/p>\n<p>In this tutorial, I am using one of the good ones \u2014 the <a href=\"https:\/\/www.anychart.com\/\">AnyChart<\/a> JS library, which has some great options for <a href=\"https:\/\/www.anychart.com\/products\/anystock\/overview\/\">stock charts<\/a> along with neat <a href=\"https:\/\/docs.anychart.com\/Stock_Charts\/Overview\" target=\"_blank\" rel=\"nofollow\">documentation<\/a> for them and is free for any non-commercial and educational use.<\/p>\n<p>Although it is not necessary, some skills with HTML and JavaScript can help understand the concepts faster. But everything is quite straightforward and will be vastly explained, so there is nothing to worry about even if you are a novice.<\/p>\n<p>The opening bell has rung, and it\u2019s time to create the stock chart!<\/p>\n<h3>1. Make an HTML page<\/h3>\n<p>The first thing I do is create an HTML page to hold the chart and add a <code>div<\/code> element to render the chart. This block element should be given a unique id so it can be referenced in the code later.<\/p>\n<p>I also set the styling of the <code>div<\/code> where I define the width and height as 100% with 0 margins and padding. This will display the stock chart over the entire screen.<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;meta charset=\"utf-8\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Stock 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%; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0height: 100%; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0margin: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0padding: 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. Add the required scripts<\/h3>\n<p>Since I am using a charting library, I need to reference the appropriate JS scripts from that library for the stock chart. Remember that these scripts are included in the <code>head<\/code> section of the HTML page.<\/p>\n<p>For a stock chart, I need to add multiple scripts. Firstly, I include 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. Next, I add the <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#data_adapter\" target=\"_blank\" rel=\"nofollow\">Data Adapter<\/a> module that helps load the data. Finally, I include the <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#common_ui\" target=\"_blank\" rel=\"nofollow\">UI<\/a> and <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#exports\" target=\"_blank\" rel=\"nofollow\">Exports<\/a> modules for user interface elements and to enable export features that let you save the chart as an image or extract the underlying data to a data file.<\/p>\n<p>For the stock UI features to work properly, I also need to link the appropriate stylesheets.<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;meta charset=\"utf-8\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Stock Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-stock.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-data-adapter.min.js\"&gt;&lt;\/script&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-ui.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-exports.min.js\"&gt;&lt;\/script&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;link href=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/css\/anychart-ui.min.css\" type=\"text\/css\" rel=\"stylesheet\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;link href=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/fonts\/css\/anychart-font.min.css\" type=\"text\/css\" rel=\"stylesheet\"&gt;\r\n\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\u00a0\u00a0&lt;script&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ All the code for the JS Stock Chart will come here\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/script&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>3. Prepare the data<\/h3>\n<p>In this stock chart, I want to visualize daily stock price data for Tesla Inc. (TSLA), so I take it from <a href=\"https:\/\/finance.yahoo.com\/quote\/TSLA\/history?p=TSLA\" target=\"_blank\" rel=\"nofollow\">Yahoo Finance<\/a> and the CSV data file <a href=\"https:\/\/gist.githubusercontent.com\/shacheeswadia\/cd509e0b0c03964ca86ae7d894137043\/raw\/5f336c644ad61728dbac93026f3268b86b8d0680\/teslaDailyData.csv\" target=\"_blank\" rel=\"nofollow\">here<\/a>.<\/p>\n<p>All the preparations are done now, so let\u2019s start the trading or in our case writing the JavaScript stock charting code!<\/p>\n<h3>4. Write the necessary JavaScript code<\/h3>\n<p>To start with, I enclose the code within a function called <code>anychart.onDocumentReady()<\/code>. This ensures that the code will not be executed till the page is fully loaded. Next, I load the data file using the <code>anychart.data.loadCsvFile()<\/code> function.<\/p>\n<p>I then create a data table and add the loaded data to it but before I can use this data for my stock chart, I need to map it. Since I am creating a candlestick stock chart, I map the open, high, low, and close values.<\/p>\n<pre><code class=\"javascript\">anychart.onDocumentReady(function () {\r\n  anychart.data.loadCsvFile(\r\n    'https:\/\/gist.githubusercontent.com\/shacheeswadia\/cd509e0b0c03964ca86ae7d894137043\/raw\/5f336c644ad61728dbac93026f3268b86b8d0680\/teslaDailyData.csv',\r\n    function (data) {\r\n      \/\/ create data table on loaded data\r\n      var dataTable = anychart.data.table();\r\n      dataTable.addData(data);\r\n\r\n      \/\/ map loaded data for the candlestick series\r\n      var mapping = dataTable.mapAs({\r\n        open: 1,\r\n        high: 2,\r\n        low: 3,\r\n        close: 4\r\n      });\r\n    }\r\n  );\r\n});<\/code><\/pre>\n<p>Now, I define the stock chart, plot it, and set the gridlines. As numbers are important when looking at stock data values, I enable all the gridlines for better readability.<\/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\/\/ set grid settings\r\nplot.yGrid(true).xGrid(true).yMinorGrid(true).xMinorGrid(true);<\/code><\/pre>\n<p>Now comes the main part of creating the series. This is done by using the candlestick drawing function with the mapping that I defined earlier. I give the series a name and add a legend icon.<\/p>\n<pre><code class=\"javascript\">var series = plot.candlestick(mapping)\r\n        .name('Tesla');\r\n\r\nseries.legendItem().iconType('rising-falling');\r\n\r\n\/\/ create scroller series with mapped data\r\nchart.scroller().candlestick(mapping);<\/code><\/pre>\n<p>Stock charts have values over a long period of time. So I add a scroller series under the main chart that enables the user to specify the date range and take a closer look at the values of that data. I set a one-year range for default display.<\/p>\n<p>To make it easier for the user, I provide both a range picker where the user can manually enter dates and a range selector where the commonly used time periods can be selected with just a click.<\/p>\n<pre><code class=\"javascript\">\/\/ set chart selected date\/time range\r\nchart.selectRange('2020-11-27', '2021-11-26');\r\n\r\n\/\/ create range picker\r\nvar rangePicker = anychart.ui.rangePicker();\r\n\r\n\/\/ init range picker\r\nrangePicker.render(chart);\r\n\r\n\/\/ create range selector\r\nvar rangeSelector = anychart.ui.rangeSelector();\r\n\r\n\/\/ init range selector\r\nrangeSelector.render(chart);<\/code><\/pre>\n<p>Finally, I give the chart a title, reference the previously defined chart container, and draw the chart.<\/p>\n<pre><code class=\"javascript\">\/\/ sets the title of the chart\r\nchart.title('Tesla Inc. Stock Chart');\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 the closing bell and a beautiful, functional stock chart is created!<\/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-Koc2SDL3\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/Koc2SDL3\/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-Koc2SDL3{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>You can quickly figure out the stock prices of Tesla have been fluctuating in the past year, but the overall trend is positive. Hover over the chart to see a functional tooltip showing the date along with open, high, low, and close values. This is one of the many useful features already available here.<\/p>\n<p>You can see this initial JS stock chart version on <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/MWEWVxy\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a>\u00a0[and on <a href=\"https:\/\/playground.anychart.com\/Koc2SDL3\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>]\u00a0with the full code.<\/p>\n<h2>Customizing the JavaScript Stock chart<\/h2>\n<p>This interactive stock chart already looks pretty good and showcases useful information that can be delved into with ease. But, this is just the beginning.<\/p>\n<p>Follow along as I\u2019ll show you how to customize the JS stock chart by adding more features (changing series, adding technical indicators, annotations, and more) and fine-tuning its visualization, all in just a handful of streamlined actions.<\/p>\n<h3>A. Series type and conditional coloring<\/h3>\n<p>A stock chart is most commonly represented with candlesticks. But it\u2019s not compulsory. Here, I want to show you how to quickly switch the type of data visualization from a candlestick stock chart, where all the four values are displayed (open, high, low, and close), to a line graph, where you can specify which value you want to plot (by default it\u2019s the first value, i.e. the opening price in this case). Since only one value is represented, the mapping that I did earlier is not required here.<\/p>\n<p>So, I simply specify the series as \u201cline\u201d and directly pass the datatable as the parameter.<\/p>\n<p>To showcase the rising and falling prices in the line stock chart, I add conditional coloring where I specify the color of the line to be red if the price is decreasing and green if it\u2019s going up. This can be very conveniently done using the in-built risingStroke and fallingStroke functions. The options to specify are the stroke color, stroke width, stroke type, and stroke endings.<\/p>\n<p>I also change the scroller series to the line graph representation.<\/p>\n<pre><code class=\"javascript\">\/\/ create and setup line series\r\nvar lineSeries = plot.line(dataTable)\r\n  .name('Tesla');\r\n\r\n\/\/ set rising\/falling and normal stroke settings\r\nlineSeries.risingStroke('#2FA85A', 3, null, 'round', 'round');\r\nlineSeries.fallingStroke('#EE4237', 3, null, 'round', 'round');\r\n\r\n\/\/ create scroller series \r\nchart.scroller().line(dataTable);<\/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-07Q4lOrV\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/07Q4lOrV\/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-07Q4lOrV{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>You can take a closer look at this new JS stock chart version on <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/jOGOxqq\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a> [and on <a href=\"https:\/\/playground.anychart.com\/07Q4lOrV\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>]. In the next steps, I go back to plotting the candlestick series to represent the data.<\/p>\n<h3>B. Technical indicators: EMA and Envelope<\/h3>\n<p>Traders and investors often rely on technical analysis to identify trends, understand whether a financial instrument is overbought or oversold, and decide when to sell or buy. And there are multiple technical indicators out there that can be helpful in that. Let\u2019s see how to quickly add them to stock charts.<\/p>\n<p>I want to include two popular technical indicators: Exponential Moving Average (EMA) and Envelope. Both these indicators can be very easily drawn with quite minimal code.<\/p>\n<p>All I have to do is map the data value that I want to use, which I specify as the closing value, indicate the stroke width and color, and the EMA line gets plotted over the candlestick chart. I can indicate the EMA period and the default is 50 if no custom value is set.<\/p>\n<p>Similarly, for the Envelope indicator, I just specify the plotting, and the lower and higher band lines are drawn over the chart.<\/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.5 #455a64');\r\n\r\n\/\/ create envelope indicator\r\nchart.plot().env(mapping);<\/code><\/pre>\n<p>Check out how this JS stock chart version with EMA and Envelope looks below. You are also welcome to play with its interactive version (and its full code) on <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/WNZNJjw\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a>\u00a0[or on <a href=\"https:\/\/playground.anychart.com\/Q2Jze1Rr\/\" target=\"_blank\" rel=\"nofollow\">AnyChart\u00a0Playground<\/a>], where you can, for example, hide and show these additional technical indicator lines by clicking on the corresponding legend items.<\/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-Q2Jze1Rr\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/Q2Jze1Rr\/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-Q2Jze1Rr{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<h3>C. MACD indicator<\/h3>\n<p>MACD or Moving Average Convergence Divergence is a momentum indicator generally plotted with a signal line. It is calculated with 26 and 12 period EMA and indicates buy or sell signs when it crosses above or below the signal line respectively.<\/p>\n<p>I plot the MACD indicator as a separate plot representing the MACD line, the signal line, and a histogram as an area chart below the candlestick chart. The first thing I do is disable the X-axis for the candlestick chart since I will have that in the MACD plot. Now, I define a second plot and map the data values.<\/p>\n<p>Next, I set the series type as an area histogram and define the stroke and fill settings for positive and negative values. Lastly, I just set the height of this plot as 40% of the total.<\/p>\n<pre><code class=\"javascript\">\/\/ second plot to show macd values\r\nvar indicatorPlot = chart.plot(1);\r\n\r\n\/\/ map the values\r\nvar macdIndicator = indicatorPlot.macd(mapping);\r\n\r\n\/\/ set series type for histogram series.\r\nmacdIndicator.histogramSeries('area');\r\n\r\nmacdIndicator\r\n  .histogramSeries()\r\n  .normal()\r\n  .fill('green .3')\r\n  .stroke('green');\r\n\r\nmacdIndicator\r\n  .histogramSeries()\r\n  .normal()\r\n  .negativeFill('red .3')\r\n  .negativeStroke('red');\r\n\r\n\/\/ set second plot's height\r\nindicatorPlot.height('40%');<\/code><\/pre>\n<h3>D. Awesome Oscillator<\/h3>\n<p>The Awesome Oscillator (AO) indicates the strength or weakness of an instrument by comparing the market momentum with the overall stock price fluctuation over a larger time reference.<\/p>\n<p>I also plot this indicator as a second chart below the main chart, just like in the previous step. I am just showing you this to bring home the point of how various technical indicators can be plotted quite easily.<\/p>\n<p>As I did for the MACD plot, similarly, I define the second plot and map the data using the ao function here for the awesome oscillator indicator.<\/p>\n<p>I specify the colors of the stroke lines as green for rising and red for falling prices and set the height of the chart to 40%.<\/p>\n<pre><code class=\"javascript\">\/\/ create awesome oscillator series\r\nvar aoIndicator = indicatorPlot.ao(mapping);\r\n\r\n\/\/ set rising and falling stroke settings\r\naoIndicator.series().risingStroke('green');\r\naoIndicator.series().fallingStroke('red');\r\n\r\n\/\/ set second plot's height\r\nindicatorPlot.height('40%');<\/code><\/pre>\n<p>If you hover over either of the top or bottom charts, you will see two icons on the top right that let you move that plot up or down as well as make it render full screen hiding the other chart.<\/p>\n<p>You can play around with these JS stock chart versions on CodePen, with the MACD plot <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/abLbGLG\" target=\"_blank\" rel=\"nofollow\">here<\/a>\u00a0[and on <a href=\"https:\/\/playground.anychart.com\/3bds3HuK\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>] and the AO plot <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/qBPBYVM\" target=\"_blank\" rel=\"nofollow\">here<\/a>\u00a0[and on <a href=\"https:\/\/playground.anychart.com\/VFhmH6Ey\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>].<\/p>\n<h3>E. Color palette<\/h3>\n<p>An easy and effective way to make your stock chart look personalized is to change the colors of the chart. The AnyChart library has pre-built design themes, so I\u2019ll just need to add the necessary script to the <code>head<\/code> section and simply set it in the code. Here, I apply a monochrome theme.<\/p>\n<pre><code class=\"html\">&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/themes\/monochrome.min.js\"&gt;&lt;\/script&gt;\r\n\r\n...\r\n\r\n\/\/ set chart theme\r\nanychart.theme('monochrome');<\/code><\/pre>\n<p>See how sophisticated and polished the stock chart looks!<\/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-69Nf8319\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/Khij8mFU\/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-69Nf8319{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>Now, in the final customization, I will show you one more cool thing that is often demanded in stock charts.<\/p>\n<h3>F. Illustrating and annotating<\/h3>\n<p>In stock charts, it may be needed to add custom objects that additionally display or highlight something. For example, in the AnyChart JS library, there is a useful feature that lets you create <a href=\"https:\/\/docs.anychart.com\/Stock_Charts\/Drawing_Tools_and_Annotations\/Overview\" target=\"_blank\" rel=\"nofollow\">drawings and annotations<\/a>.<\/p>\n<p>I will show you here how to highlight a specific period and also provide it with an explanatory note. I will showcase the time when the stock prices of Tesla fell due to Elon Musk selling a bunch of his own stocks.<\/p>\n<p>To start, I define the annotation and then create a rectangle. I set the various parameters like the width and height of the rectangle along with the dates that indicate the starting and ending of the rectangle. I also set the stroke and fill values where I choose the red color from the company\u2019s logo.<\/p>\n<p>Next, I create the annotation label below the rectangle. I again define where to start the label, the dimensions, the colors, and, of course, the text.<\/p>\n<pre><code class=\"javascript\">\/\/ create annotation rectangle\r\nannotation.rectangle({\r\n  \/\/ X - part of the first anchor\r\n  xAnchor: '2021-11-08',\r\n  \/\/ Y - part of the first anchor\r\n  valueAnchor: 950,\r\n  \/\/ X - part of the second anchor\r\n  secondXAnchor: '2021-11-26',\r\n  \/\/ Y - part of the second anchor\r\n  secondValueAnchor: 1250,\r\n  \/\/ set stroke settings\r\n  stroke: '3 #c20000',\r\n  \/\/ set fill settings\r\n  fill: '#c20000 0.25'\r\n});\r\n      \r\n\/\/ create annotation and set settings\r\nannotation\r\n  .label()\r\n  .xAnchor('2021-11-26')\r\n  .valueAnchor(950)\r\n  .anchor('right-top')\r\n  .offsetY(5)\r\n  .padding(6)\r\n  .text('Elon Musk sells Tesla stock worth $1.05 billion')\r\n  .fontColor('#fff')\r\n  .background({\r\n    fill: '#c20000 0.75',\r\n    stroke: '0.5 #c20000',\r\n    corners: 2\r\n  });<\/code><\/pre>\n<p>This was just a simple illustration. If you want to learn more about how such drawing and annotation options can look and work in real life, play with this <a href=\"https:\/\/www.anychart.com\/solutions\/drawing-tools\/\">demo tool<\/a>.<\/p>\n<p>And that wraps up the customizations, and a lovely, interactive, and insightful JS stock chart is all done. Take a look at the final version below. Doesn\u2019t it look like something you will put your money on? You can look into the full HTML\/CSS\/JavaScript code and keep customizing this stock chart to your liking on <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/wvrvXrr\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a> [or on <a href=\"https:\/\/playground.anychart.com\/69Nf8319\/\" target=\"_blank\" rel=\"nofollow\">AnyChart 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-69Nf8319\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/69Nf8319\/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-69Nf8319{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<h2>Conclusion<\/h2>\n<p>As you can see, creating a stylish interactive stock chart with technical indicators and annotations looks complicated initially but can be quite hassle-free and convenient in reality. <a href=\"https:\/\/en.wikipedia.org\/wiki\/Comparison_of_JavaScript_charting_libraries\" target=\"_blank\" rel=\"nofollow\">JavaScript charting libraries<\/a> are many, and the process of building a stock chart is similar for most of those that support this chart type. So you can choose which one to use based on your requirements and particular tasks.<\/p>\n<p>In this tutorial, I showed you how to create one type of stock chart \u2014 candlestick \u2014 and explained how to quickly change the series making a line one out of it. But there are also other interesting stock chart types that you can look at closer by yourself, for example, <a href=\"https:\/\/www.anychart.com\/products\/anystock\/gallery\/Stock_Chart_Types\/\">here<\/a>.<\/p>\n<p>Go on then, create stock charts and see if you can predict what will happen next. Of course, no particular stock can be a sure shot bet in the stock markets. But learning how to plot one is definitely guaranteed to be a winning decision! Please get in touch if you need any help.<\/p>\n<hr \/>\n<p><em>Published with the permission of Shachee Swadia. Originally appeared on <a href=\"https:\/\/betterprogramming.pub\/how-to-create-a-stock-chart-in-javascript-c250769045c2\" target=\"_blank\" rel=\"nofollow\">Better Programming<\/a> with the title <em>&#8220;Build a Stock Chart Using AnyChart JavaScript Library&#8221;<\/em> on January 4, 2022.<\/p>\n<p>See more about stock charts on <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/stock-chart\/\">Chartopedia<\/a>, a free guide to chart types. Check out other <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JavaScript charting tutorials<\/a>.<\/p>\n<p>Would you like to create a cool guest post for our blog? We can&#8217;t wait to <a href=\"https:\/\/www.anychart.com\/support\/\"> hear from you<\/a> to discuss your ideas.<\/em><\/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>Data visualization is vastly applied in various fields. One such domain is financial trading, where stock charts are essential for smart market data analysis and decision making. Whether you invest in stocks or not, I am pretty sure that you have come across such graphics or even might need to build one right now. So, [&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,619,618,2033,53,93,289,265,3219,268,198,254,1758,3149,284,166,258,2012,471,266,620,916,1292,880,806,509,195,2220,2838,54,1389,1760,2757,256,1111,350,842,844,165,313,1370,133,774,775,100,2032,3217,47,912,805,914,1762,913,2013,2014,32,55,144,151,36,907,141,249,3111,81,57,169,170,1238,142,96,99,58,65,56,101,911,2387,2388,199,2841,459,200,37,910,915,1958,1959,1960,3220,248,587,589,3215,3216,3214,30,172,807,808,954,293,899,2816,1763,804,3218],"class_list":["post-14418","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-analysis","tag-analytics","tag-annotations","tag-anychart","tag-anystock","tag-api","tag-big-data","tag-big-data-apps","tag-big-data-tools","tag-candlestick-chart","tag-chart","tag-chart-design","tag-chart-development","tag-chart-examples","tag-charting","tag-charts","tag-csv-data-visualization","tag-data-analysis","tag-data-analytics","tag-data-analytics-examples","tag-data-api","tag-data-chart","tag-data-charting","tag-data-charts","tag-data-graphics","tag-data-over-time","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-tutorial","tag-data-visualizations","tag-data-visuals","tag-data-viz-examples","tag-dataviz","tag-dataviz-examples","tag-dataviz-projects","tag-drawing-in-javascript","tag-drawing-tools","tag-elon-musk","tag-financial-charts","tag-financial-data","tag-front-end-development","tag-fundamental-financial-data","tag-guest-post","tag-historical-stock-prices","tag-html","tag-html-charts","tag-html5","tag-html5-charts","tag-infographics","tag-interactive-visualizations","tag-javascript","tag-javascript-chart-tutorial","tag-javascript-charting","tag-javascript-charting-api","tag-javascript-charting-features","tag-javascript-charting-library","tag-javascript-charts","tag-javascript-drawing","tag-javascript-drawing-library","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-market-data","tag-market-data-visualization","tag-ohlc-chart","tag-open-high-low-close-chart","tag-statistics","tag-stock-chart","tag-stock-charts","tag-stock-data","tag-stock-data-feed","tag-stock-market","tag-stock-market-data","tag-stock-market-data-visualization","tag-technical-analysis","tag-technical-indicators","tag-tesla","tag-tesla-charts","tag-tesla-stock-chart","tag-tesla-stock-price","tag-tesla-stocks","tag-tips-and-tricks","tag-tutorial","tag-visual-analysis","tag-visual-analytics","tag-visual-data-analytics","tag-visualization","tag-visualizations","tag-web-design","tag-web-developers","tag-web-development","tag-yahoo-finance","wpautop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Stock Chart: What Is It &amp; How to Build One with JavaScript<\/title>\n<meta name=\"description\" content=\"Learn what a stock chart is and how to code a cool interactive one using JavaScript. Visualizing data for Tesla stocks prices since 2010 along the tutorial.\" \/>\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\/2022\/02\/24\/stock-chart-js\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What Is Stock Chart &amp; How to Build It in JavaScript\" \/>\n<meta property=\"og:description\" content=\"Learn what a stock chart is and how to develop it using JavaScript. Visualizing Tesla stock price data along the tutorial.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/\" \/>\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=\"2022-02-24T13:37:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-13T11:10:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js-social.png\" \/>\n<meta name=\"author\" content=\"Shachee Swadia\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"What Is Stock Chart &amp; How to Build It in JavaScript\" \/>\n<meta name=\"twitter:description\" content=\"Learn what a stock chart is and how to develop it using JavaScript. Visualizing Tesla stock price data along the tutorial.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js-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=\"16 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/\"},\"author\":{\"name\":\"Shachee Swadia\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"headline\":\"Building Stock Chart with JavaScript\",\"datePublished\":\"2022-02-24T13:37:03+00:00\",\"dateModified\":\"2022-08-13T11:10:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/\"},\"wordCount\":2505,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js.png\",\"keywords\":[\"advanced data visualization\",\"analysis\",\"analytics\",\"annotations\",\"AnyChart\",\"AnyStock\",\"api\",\"big data\",\"big data apps\",\"big data tools\",\"candlestick chart\",\"chart\",\"chart design\",\"chart development\",\"chart examples\",\"charting\",\"charts\",\"CSV data visualization\",\"data analysis\",\"data analytics\",\"data analytics examples\",\"data API\",\"data chart\",\"data charting\",\"data charts\",\"data graphics\",\"data over time\",\"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 tutorial\",\"data visualizations\",\"data visuals\",\"data viz examples\",\"dataviz\",\"dataviz examples\",\"dataviz projects\",\"drawing in JavaScript\",\"drawing tools\",\"Elon Musk\",\"Financial charts\",\"financial data\",\"front-end development\",\"fundamental financial data\",\"guest post\",\"historical stock prices\",\"HTML\",\"HTML charts\",\"HTML5\",\"html5 charts\",\"infographics\",\"interactive visualizations\",\"JavaScript\",\"javascript chart tutorial\",\"javascript charting\",\"javascript charting api\",\"JavaScript charting features\",\"JavaScript charting library\",\"javascript charts\",\"javascript drawing\",\"javascript drawing library\",\"javascript graph\",\"javascript graphics\",\"JavaScript graphics library\",\"JavaScript library\",\"js chart\",\"js charting\",\"js charts\",\"JS graphics\",\"JS stock chart\",\"market data\",\"market data visualization\",\"ohlc chart\",\"open-high-low-close chart\",\"statistics\",\"stock chart\",\"Stock charts\",\"stock data\",\"stock data feed\",\"stock market\",\"stock market data\",\"stock market data visualization\",\"technical analysis\",\"technical indicators\",\"Tesla\",\"Tesla charts\",\"Tesla stock chart\",\"Tesla stock price\",\"Tesla stocks\",\"Tips and tricks\",\"tutorial\",\"visual analysis\",\"visual analytics\",\"visual data analytics\",\"visualization\",\"visualizations\",\"web design\",\"web developers\",\"web development\",\"Yahoo Finance\"],\"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\/2022\/02\/24\/stock-chart-js\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/\",\"name\":\"Stock Chart: What Is It & How to Build One with JavaScript\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js.png\",\"datePublished\":\"2022-02-24T13:37:03+00:00\",\"dateModified\":\"2022-08-13T11:10:20+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"description\":\"Learn what a stock chart is and how to code a cool interactive one using JavaScript. Visualizing data for Tesla stocks prices since 2010 along the tutorial.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js.png\",\"width\":1500,\"height\":843},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Building Stock Chart with 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":"Stock Chart: What Is It & How to Build One with JavaScript","description":"Learn what a stock chart is and how to code a cool interactive one using JavaScript. Visualizing data for Tesla stocks prices since 2010 along the tutorial.","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\/2022\/02\/24\/stock-chart-js\/","og_locale":"en_US","og_type":"article","og_title":"What Is Stock Chart & How to Build It in JavaScript","og_description":"Learn what a stock chart is and how to develop it using JavaScript. Visualizing Tesla stock price data along the tutorial.","og_url":"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2022-02-24T13:37:03+00:00","article_modified_time":"2022-08-13T11:10:20+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js-social.png","type":"","width":"","height":""}],"author":"Shachee Swadia","twitter_card":"summary_large_image","twitter_title":"What Is Stock Chart & How to Build It in JavaScript","twitter_description":"Learn what a stock chart is and how to develop it using JavaScript. Visualizing Tesla stock price data along the tutorial.","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js-social.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Shachee Swadia","Est. reading time":"16 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/"},"author":{"name":"Shachee Swadia","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"headline":"Building Stock Chart with JavaScript","datePublished":"2022-02-24T13:37:03+00:00","dateModified":"2022-08-13T11:10:20+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/"},"wordCount":2505,"commentCount":0,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js.png","keywords":["advanced data visualization","analysis","analytics","annotations","AnyChart","AnyStock","api","big data","big data apps","big data tools","candlestick chart","chart","chart design","chart development","chart examples","charting","charts","CSV data visualization","data analysis","data analytics","data analytics examples","data API","data chart","data charting","data charts","data graphics","data over time","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 tutorial","data visualizations","data visuals","data viz examples","dataviz","dataviz examples","dataviz projects","drawing in JavaScript","drawing tools","Elon Musk","Financial charts","financial data","front-end development","fundamental financial data","guest post","historical stock prices","HTML","HTML charts","HTML5","html5 charts","infographics","interactive visualizations","JavaScript","javascript chart tutorial","javascript charting","javascript charting api","JavaScript charting features","JavaScript charting library","javascript charts","javascript drawing","javascript drawing library","javascript graph","javascript graphics","JavaScript graphics library","JavaScript library","js chart","js charting","js charts","JS graphics","JS stock chart","market data","market data visualization","ohlc chart","open-high-low-close chart","statistics","stock chart","Stock charts","stock data","stock data feed","stock market","stock market data","stock market data visualization","technical analysis","technical indicators","Tesla","Tesla charts","Tesla stock chart","Tesla stock price","Tesla stocks","Tips and tricks","tutorial","visual analysis","visual analytics","visual data analytics","visualization","visualizations","web design","web developers","web development","Yahoo Finance"],"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\/2022\/02\/24\/stock-chart-js\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/","url":"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/","name":"Stock Chart: What Is It & How to Build One with JavaScript","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js.png","datePublished":"2022-02-24T13:37:03+00:00","dateModified":"2022-08-13T11:10:20+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"description":"Learn what a stock chart is and how to code a cool interactive one using JavaScript. Visualizing data for Tesla stocks prices since 2010 along the tutorial.","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/stock-chart-js.png","width":1500,"height":843},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/24\/stock-chart-js\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Building Stock Chart with 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\/14418","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=14418"}],"version-history":[{"count":21,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14418\/revisions"}],"predecessor-version":[{"id":15524,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14418\/revisions\/15524"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=14418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=14418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=14418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}