{"id":15672,"date":"2022-09-14T09:00:33","date_gmt":"2022-09-14T09:00:33","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=15672"},"modified":"2023-10-31T14:44:35","modified_gmt":"2023-10-31T14:44:35","slug":"line-chart-in-javascript","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/","title":{"rendered":"Making Line Chart \u2014 and Step Line Chart \u2014 in JavaScript"},"content":{"rendered":"<p><a href=\"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/\"><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-chart.png\" alt=\"Line Chart in JavaScript (HTML5)\" width=\"100%\" class=\"alignnone size-full wp-image-15678\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-chart.png 1800w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-chart-300x158.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-chart-768x403.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-chart-1024x538.png 1024w\" sizes=\"(max-width: 1800px) 100vw, 1800px\" \/><\/a>Data visualization is a vast field with so many different <a href=\"https:\/\/www.anychart.com\/chartopedia\/\">types of charts<\/a> to learn and create. But there are several basic, evergreen graphs that every data designer and web developer dealing with analytics should know how to build. One of them is a <strong>Line Chart<\/strong> (or <strong>Line Graph<\/strong>). It&#8217;s primarily designed to represent data over time.<\/p>\n<p>You can follow along with this tutorial to learn how to quickly create beautiful interactive line (and step-line) charts using JavaScript. We&#8217;ll look at some cool examples and build them step by step, which will make the process both clear and entertaining.<\/p>\n<p>For your convenience, you can find all of them on <a href=\"https:\/\/codepen.io\/collection\/pgPwyr\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a> [and on <a href=\"https:\/\/playground.anychart.com\/nrB9tKMK\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>] so you could play with the line charting code further without limits.<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2>Our Dataset<\/h2>\n<p>The last two decades have been nothing short of spectacular in the world of tennis. <a href=\"https:\/\/en.wikipedia.org\/wiki\/Big_Three_(tennis)#Grand_Slam_tournaments\" target=\"_blank\" rel=\"nofollow\">The Big Three<\/a> \u2014 Roger Federer, Rafael Nadal, and Novak Djokovic \u2014 have won an astonishing combined 63 (of the past 78) Grand Slam tournaments. These are the most prestigious championships.<\/p>\n<p>I decided to plot their outstanding rivalry. So, the JS line graphs in this tutorial will visualize <strong>the Big Three\u2019s Grand Slam title race<\/strong>. And the first serve is already coming!<\/p>\n<h2>How to Build Line Charts in 4 Steps<\/h2>\n<p>Generally speaking, the whole process of creating any chart in JavaScript is broken down into four steps, and a line chart is no exception:<\/p>\n<ol>\n<li>Make an HTML page with a container.<\/li>\n<li>Include JavaScript files.<\/li>\n<li>Add your data.<\/li>\n<li>Code a visualization.<\/li>\n<\/ol>\n<p>Let&#8217;s go through each of these steps now.<\/p>\n<h3>1. Make an HTML page with a container<\/h3>\n<p>To start with, you need a place where you want your chart to appear.<\/p>\n<p>If you don\u2019t have one yet, create a basic web page. Then create a container for the line chart \u2014 add an HTML block-level element and give it a unique ID for further reference.<\/p>\n<p>Here\u2019s what such a page might look like:<\/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;Line Chart JS&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<p>The <code>width<\/code> and <code>height<\/code> parameters of the element are set as 100%. As a result, the line chart will render all over the web page. Of course you can set the style settings to your own liking and needs.<\/p>\n<h3>2. Include JavaScript files<\/h3>\n<p>Next, include all JavaScript files, which we&#8217;ll use to create the line chart, in the <code>&lt;head&gt;<\/code> section.<\/p>\n<p>There are a whole lot of different <a href=\"https:\/\/en.wikipedia.org\/wiki\/Comparison_of_JavaScript_charting_libraries\" target=\"_blank\" rel=\"nofollow\">JavaScript charting libraries<\/a> which let you visualize data in a fast and simple way. Many of them support line charts, and you can choose one or another depending on your project requirements.<\/p>\n<p>For illustration purposes, in this tutorial, I am using <a href=\"https:\/\/www.anychart.com\">AnyChart JS Charts<\/a>. It\u2019s flexible, comes with extensive <a href=\"https:\/\/docs.anychart.com\/\" target=\"_blank\" rel=\"nofollow\">charting docs<\/a> and <a href=\"https:\/\/api.anychart.com\/\" target=\"_blank\" rel=\"nofollow\">API references<\/a>, and you can use it for free (unless you are building something for a business.)<\/p>\n<p>For the line chart, I add the \u201cBase\u201d module from the <a href=\"https:\/\/www.anychart.com\/download\/cdn\/\">CDN<\/a>. (Of course, you can download it, put it in a folder on your website, and use your own link in that case.)<\/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;Line Chart JS&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-base.min.js\"&gt;&lt;\/script&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\u00a0\u00a0&lt;script&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ JavaScript code for the line chart.\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/script&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<p>The JavaScript code for the line graph will be inserted between <code>&lt;script&gt;<\/code> and <code>&lt;\/script&gt;<\/code> tags located in the <code>&lt;body&gt;<\/code> section (you may put those in the <code>&lt;head&gt;<\/code> section if you want).<\/p>\n<h3>3. Add your data<\/h3>\n<p>Then, add the data you want to visualize in your line chart.<\/p>\n<p>I counted all <a href=\"https:\/\/en.wikipedia.org\/wiki\/Big_Three_(tennis)#Grand_Slam_tournaments\" target=\"_blank\" rel=\"nofollow\">Grand Slam singles titles won by Federer, Nadal, and Djokovic<\/a>, by year. I will add it just like that as an array of arrays.<\/p>\n<p>If you prefer other formats in your particular case, such as JSON, XML, CSV, or something else, check the <a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Overview\" target=\"_blank\" rel=\"nofollow\">ways to work with data<\/a>.<\/p>\n<pre><code class=\"javascript\">var data = [\r\n  [\"2003\", 1, 0, 0],\r\n  [\"2004\", 4, 0, 0],\r\n  [\"2005\", 6, 0, 0],\r\n  [\"2006\", 9, 1, 0],\r\n  [\"2007\", 12, 2, 0],\r\n  [\"2008\", 13, 5, 1],\r\n  [\"2009\", 15, 6, 1],\r\n  [\"2010\", 16, 9, 1],\r\n  [\"2011\", 16, 10, 4],\r\n  [\"2012\", 17, 11, 5],\r\n  [\"2013\", 17, 13, 6],\r\n  [\"2014\", 17, 14, 7],\r\n  [\"2015\", 17, 14, 10],\r\n  [\"2016\", 17, 14, 12],\r\n  [\"2017\", 19, 16, 12],\r\n  [\"2018\", 20, 17, 14],\r\n  [\"2019\", 20, 19, 16],\r\n  [\"2020\", 20, 20, 17],\r\n  [\"2021\", 20, 20, 20],\r\n  [\"2022\", 20, 22, 20]\r\n];<\/code><\/pre>\n<p>In each array, the year is the first parameter (column #0). Then comes the number of titles won by the three players subsequently (cumulative for each).<\/p>\n<h3>4. Code a visualization<\/h3>\n<p>Now, the warm-up session is done, and the court is all set. So let\u2019s get the match started and do some quick JavaScript coding!<\/p>\n<p>First, add <code>anychart.onDocumentReady()<\/code> as shown below:<\/p>\n<pre><code class=\"html\">&lt;script&gt;\r\n  anychart.onDocumentReady(function() {\r\n    \/\/ The main JS line charting code will be here.\r\n  });\r\n&lt;\/script&gt;<\/code><\/pre>\n<p>Everything else goes inside of that function.<\/p>\n<p>So, second, include the data (from the previous step).<\/p>\n<p>Third, create a data set and map it for each series (one for each player):<\/p>\n<pre><code class=\"javascript\">\/\/ create a data set\r\nvar dataSet = anychart.data.set(data);\r\n\r\n\/\/ map the data for all series\r\nvar firstSeriesData = dataSet.mapAs({x: 0, value: 1});\r\nvar secondSeriesData = dataSet.mapAs({x: 0, value: 2});\r\nvar thirdSeriesData = dataSet.mapAs({x: 0, value: 3});<\/code><\/pre>\n<p>Fourth, create a line chart instance and three series with the mapped data:<\/p>\n<pre><code class=\"javascript\">\/\/ create a line chart\r\nvar chart = anychart.line();\r\n\r\n\/\/ create the series and name them\r\nvar firstSeries = chart.line(firstSeriesData);\r\nfirstSeries.name(\"Roger Federer\");\r\nvar secondSeries = chart.line(secondSeriesData);\r\nsecondSeries.name(\"Rafael Nadal\");\r\nvar thirdSeries = chart.line(thirdSeriesData);\r\nthirdSeries.name(\"Novak Djokovic\");<\/code><\/pre>\n<p>Fifth, to make it clear at a glance what is shown in the line chart, a good idea is to add a legend and a title:<\/p>\n<pre><code class=\"javascript\">\/\/ add a legend\r\nchart.legend().enabled(true);\r\n  \r\n\/\/ add a title\r\nchart.title(\"Big Three's Grand Slam Title Race\");<\/code><\/pre>\n<p>Finally, reference the container element ID and draw the resulting line chart:<\/p>\n<pre><code class=\"javascript\">\/\/ specify where to display the chart\r\nchart.container(\"container\");\r\n  \r\n\/\/ draw the resulting chart\r\nchart.draw();<\/code><\/pre>\n<p>That\u2019s it! A fully functional line graph built with JS is ready. Feels like a <a href=\"https:\/\/sports.answers.com\/Q\/What_does_straight_sets_mean_in_a_game_of_tennis\" target=\"_blank\" rel=\"nofollow\">straight-sets<\/a> victory, doesn\u2019t it?<\/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-wIbBdukI\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/wIbBdukI\/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-wIbBdukI{width:100%;height:450px;}\");\n})();<\/script><\/p>\n<p>Check out this basic version of the line chart with the full HTML\/CSS\/JS code on <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/gOvjVaK\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a> [or on <a href=\"https:\/\/playground.anychart.com\/wIbBdukI\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>]. Just in case, here\u2019s the code too:<\/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;Line Chart JS&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-base.min.js\"&gt;&lt;\/script&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\u00a0\u00a0&lt;script&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0anychart.onDocumentReady(function () {\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ add data\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var data = [\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2003\", 1, 0, 0],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2004\", 4, 0, 0],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2005\", 6, 0, 0],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2006\", 9, 1, 0],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2007\", 12, 2, 0],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2008\", 13, 5, 1],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2009\", 15, 6, 1],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2010\", 16, 9, 1],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2011\", 16, 10, 4],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2012\", 17, 11, 5],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2013\", 17, 13, 6],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2014\", 17, 14, 7],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2015\", 17, 14, 10],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2016\", 17, 14, 12],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2017\", 19, 16, 12],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2018\", 20, 17, 14],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2019\", 20, 19, 16],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2020\", 20, 20, 17],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2021\", 20, 20, 20],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2022\", 20, 22, 20]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0];\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ create a data set\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var dataSet = anychart.data.set(data);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ map the data for all series\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var firstSeriesData = dataSet.mapAs({x: 0, value: 1});\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var secondSeriesData = dataSet.mapAs({x: 0, value: 2});\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var thirdSeriesData = dataSet.mapAs({x: 0, value: 3});\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ create a line chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var chart = anychart.line();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ create the series and name them\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var firstSeries = chart.line(firstSeriesData);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0firstSeries.name(\"Roger Federer\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var secondSeries = chart.line(secondSeriesData);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0secondSeries.name(\"Rafael Nadal\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var thirdSeries = chart.line(thirdSeriesData);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0thirdSeries.name(\"Novak Djokovic\");\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ add a legend\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.legend().enabled(true);\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ add a title\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.title(\"Big Three's Grand Slam Title Race\");\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ specify where to display the chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.container(\"container\");\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ draw the resulting chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.draw();\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/script&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2>How to Customize Your Line Charts<\/h2>\n<p>The basic line chart we created by following the four steps above already looks good. But what if you want to customize it?<\/p>\n<p>Let me show you how to make some changes in the same quick and easy manner.<\/p>\n<h3>1. Name the axes<\/h3>\n<p>It is always a good idea to explain what each axis of the line chart represents, even if it seems quite obvious. To add titles to both the X and Y axes, use the following:<\/p>\n<pre><code class=\"javascript\">chart.yAxis().title(\"Titles won\");\r\nchart.xAxis().title(\"Year\");<\/code><\/pre>\n<h3>2. Customize the markers<\/h3>\n<p>By default, when you move the mouse pointer over the plot, markers show up on each line series, and their shapes are different. Why not give the markers the same shape? Plus, it would be great to make them smaller.<\/p>\n<p>Look how you can customize the appearance of the line series markers:<\/p>\n<pre><code class=\"javascript\">firstSeries.hovered().markers().type(\"circle\").size(4);\r\nsecondSeries.hovered().markers().type(\"circle\").size(4);\r\nthirdSeries.hovered().markers().type(\"circle\").size(4);<\/code><\/pre>\n<h3>3. Enable crosshairs<\/h3>\n<p>Crosshairs are a pair of perpendicular lines following the mouse pointer to help you better understand the X and Y values at any currently hovered point.<\/p>\n<p>In this case, it could be enough to get only one such line, vertical, to highlight the year. Here\u2019s how it\u2019s done:<\/p>\n<pre><code class=\"javascript\">chart.crosshair().enabled(true).yStroke(null).yLabel(false);<\/code><\/pre>\n<h3>4. Change the tooltip position<\/h3>\n<p>Currently, the tooltip is following the mouse pointer. But in this situation, it could be better to make it stick to the data points.<\/p>\n<p>To achieve that kind of behavior, just define the line chart tooltip position mode as \u201cpoint\u201d and fine-tune other position settings to your liking. For example:<\/p>\n<pre><code class=\"javascript\">chart.tooltip().positionMode(\"point\");\r\nchart.tooltip().position(\"right\").anchor(\"left-center\").offsetX(5).offsetY(5);<\/code><\/pre>\n<p>Check out how the JavaScript line chart looks now after all these customizations. (See it live with the full code on <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/vYdaoyR\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a> [or on <a href=\"https:\/\/playground.anychart.com\/dvst5mzW\/\" 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-dvst5mzW\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/dvst5mzW\/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-dvst5mzW{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<h3>5. Change the colors<\/h3>\n<p>One of the simplest, yet most effective ways to personalize a data visualization is by playing with the colors.<\/p>\n<p>The code below changes the color of each player\u2019s line to the main color of the Grand Slam tournament he has won the most times: Wimbledon\u2019s purple for Federer, French Open\u2019s brown for Nadal, and Australian Open\u2019s blue for Djokovic. Additionally, the thickness of the lines is adjusted.<\/p>\n<pre><code class=\"javascript\">firstSeries.normal().stroke(\"#7b60a2\", 2.5);\r\nsecondSeries.normal().stroke(\"#db7346\", 2.5);\r\nthirdSeries.normal().stroke(\"#43a7dc\", 2.5);<\/code><\/pre>\n<h3>6. Improve the title and legend text<\/h3>\n<p>The last changes I want to demonstrate in this tutorial \u2014 and make the interactive line chart complete \u2014 are title and legend customizations.<\/p>\n<p>You can add a subtitle to provide more context, and you can make the text styling more attractive in a few quick tweaks with the help of HTML:<\/p>\n<pre><code class=\"javascript\">chart\r\n  .title()\r\n  .enabled(true)\r\n  .useHtml(true)\r\n  .text(\r\n    '&lt;span style=\"color: #006331; font-size:20px;\"&gt;Big Three's Grand Slam Title Race&lt;\/span&gt;' +\r\n      '&lt;br\/&gt;&lt;span style=\"font-size: 16px;\"&gt;(Triumphs at Australian Open, French Open, Wimbledon, U.S. Open)&lt;\/span&gt;'\r\n  );<\/code><\/pre>\n<p>For the chart legend, it\u2019s easy to modify the font size and the padding:<\/p>\n<pre><code>chart.legend().enabled(true).fontSize(14).padding([10, 0, 10, 0]);<\/code><\/pre>\n<p>See what we\u2019ve got! (Check out this JS line chart on <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/wvyxVqZ\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a> [or on <a href=\"https:\/\/playground.anychart.com\/7y7cqB6G\/\" 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-7y7cqB6G\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/7y7cqB6G\/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-7y7cqB6G{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<h2>How to Create a Step Line Chart<\/h2>\n<p>Just like it\u2019s always more exciting when a tennis match is a five-setter one, here is something extra to make this tutorial and this line graph visualization even more awesome.<\/p>\n<p>From the point of view of data visualization, a stepped line chart will actually work better in this case. And we can make one with just one small modification.<\/p>\n<p>Just change the <code>line()<\/code> function to <code>stepLine()<\/code> and your line chart will become your stepped line chart:<\/p>\n<pre><code class=\"javascript\">\/\/ create a stepped line chart\r\nvar chart = anychart.stepLine();\r\n\r\n\/\/ create the series and name them\r\nvar firstSeries = chart.stepLine(firstSeriesData);\r\nfirstSeries.name(\"Roger Federer\");\r\nvar secondSeries = chart.stepLine(secondSeriesData);\r\nsecondSeries.name(\"Rafael Nadal\");\r\nvar thirdSeries = chart.stepLine(thirdSeriesData);\r\nthirdSeries.name(\"Novak Djokovic\");<\/code><\/pre>\n<p>Enjoy the elegant JavaScript-powered stepped line chart visualizing the Grand Slam title race between the Big Three in tennis. (Feel free to explore and continue playing with its full source code on <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/zYRmXpv\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a> [or on <a href=\"https:\/\/playground.anychart.com\/nrB9tKMK\/\" 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-nrB9tKMK\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/nrB9tKMK\/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-nrB9tKMK{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>And here&#8217;s the full code:<\/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;Line Chart JS&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-base.min.js\"&gt;&lt;\/script&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\u00a0\u00a0&lt;script&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0anychart.onDocumentReady(function () {\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ add data\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var data = [\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2003\", 1, 0, 0],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2004\", 4, 0, 0],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2005\", 6, 0, 0],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2006\", 9, 1, 0],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2007\", 12, 2, 0],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2008\", 13, 5, 1],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2009\", 15, 6, 1],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2010\", 16, 9, 1],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2011\", 16, 10, 4],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2012\", 17, 11, 5],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2013\", 17, 13, 6],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2014\", 17, 14, 7],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2015\", 17, 14, 10],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2016\", 17, 14, 12],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2017\", 19, 16, 12],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2018\", 20, 17, 14],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2019\", 20, 19, 16],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2020\", 20, 20, 17],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2021\", 20, 20, 20],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2022\", 20, 22, 20]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0];\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ create a data set\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var dataSet = anychart.data.set(data);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ map the data for all series\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var firstSeriesData = dataSet.mapAs({x: 0, value: 1});\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var secondSeriesData = dataSet.mapAs({x: 0, value: 2});\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var thirdSeriesData = dataSet.mapAs({x: 0, value: 3});\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ create a stepped line chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var chart = anychart.stepLine();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ create the series and name them\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var firstSeries = chart.stepLine(firstSeriesData);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0firstSeries.name(\"Roger Federer\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var secondSeries = chart.stepLine(secondSeriesData);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0secondSeries.name(\"Rafael Nadal\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var thirdSeries = chart.stepLine(thirdSeriesData);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0thirdSeries.name(\"Novak Djokovic\");\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ add a legend and customize it\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.legend().enabled(true).fontSize(14).padding([10, 0, 10, 0]);\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ add a title and customize it\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.title()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.enabled(true)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.useHtml(true)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.text(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'&lt;span style=\"color: #006331; font-size:20px;\"&gt;Big Three&amp;#39;s Grand Slam Title Race&lt;\/span&gt;' +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'&lt;br\/&gt;&lt;span style=\"font-size: 16px;\"&gt;(Triumphs at Australian Open, French Open, Wimbledon, U.S. Open)&lt;\/span&gt;'\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0);\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ name the axes\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.yAxis().title(\"Titles won\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.xAxis().title(\"Year\");\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ customize the series markers\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0firstSeries.hovered().markers().type(\"circle\").size(4);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0secondSeries.hovered().markers().type(\"circle\").size(4);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0thirdSeries.hovered().markers().type(\"circle\").size(4);\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ turn on crosshairs and remove the y hair\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.crosshair().enabled(true).yStroke(null).yLabel(false);\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ change the tooltip position\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.tooltip().positionMode(\"point\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.tooltip().position(\"right\").anchor(\"left-center\").offsetX(5).offsetY(5);\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ customize the series stroke in the normal state\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0firstSeries.normal().stroke(\"#7b60a2\", 2.5);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0secondSeries.normal().stroke(\"#db7346\", 2.5);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0thirdSeries.normal().stroke(\"#43a7dc\", 2.5);\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ specify where to display the chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.container(\"container\");\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ draw the resulting chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.draw();\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/script&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>As you can see in this tutorial, creating interactive line (and stepped line) charts with JavaScript can be pretty straightforward. Let me know if you have any questions or suggestions.<\/p>\n<p>It is motivating to see how these greats have achieved so much in their professional life.<\/p>\n<p>Let\u2019s use this inspiration to get ahead in the field of data visualization development by building even more (and all the more awesome) charts and graphs!<\/p>\n<hr \/>\n<p><strong><em>Published with the permission of Shachee Swadia. Originally appeared on <a href=\"https:\/\/www.freecodecamp.org\/news\/how-to-make-line-charts-in-javascript\/\" target=\"_blank\" rel=\"nofollow\">freeCodeCamp<\/a> with the title <em>&#8220;Line Charts Tutorial \u2013 How to Create a Line Graph in JavaScript&#8221;<\/em> on September 8, 2022.<\/p>\n<p>You may also like to check out the JavaScript <a href=\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/\">Line Chart Tutorial<\/a> originally published on our blog last year.<\/p>\n<p>Don&#8217;t miss our other awesome <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JavaScript charting tutorials<\/a>!<\/em><\/strong><\/p>\n<hr \/>\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 a vast field with so many different types of charts to learn and create. But there are several basic, evergreen graphs that every data designer and web developer dealing with analytics should know how to build. One of them is a Line Chart (or Line Graph). It&#8217;s primarily designed to represent data [&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,23,13,279,4],"tags":[53,3173,260,3433,1758,284,258,471,266,620,1759,3352,509,2220,2838,54,1389,1760,2757,256,1111,744,844,165,313,1370,774,3369,1498,3432,3435,2260,805,1762,2013,2014,32,55,144,2979,2016,433,36,907,141,249,3111,81,57,1238,142,96,99,58,65,56,101,2684,196,106,3434,1509,2686,459,197,3436,3099,30,172,807,808,3100,745,899,2836,2816,1763,804,3406,3407],"class_list":["post-15672","post","type-post","status-publish","format-standard","hentry","category-anychart-charting-component","category-html5","category-javascript","category-javascript-chart-tutorials","category-tips-and-tricks","tag-anychart","tag-app-development","tag-best-data-visualization-examples","tag-billionaires","tag-chart-design","tag-chart-examples","tag-charts","tag-data-analysis","tag-data-analytics","tag-data-analytics-examples","tag-data-design","tag-data-graphic","tag-data-graphics","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-techniques","tag-data-visualization-tutorial","tag-data-visualizations","tag-data-visuals","tag-data-viz-examples","tag-dataviz-examples","tag-developers","tag-example","tag-forbes","tag-forbes-billionaires-2022","tag-freecodecamp","tag-front-end-development","tag-guest-post","tag-html","tag-html-charts","tag-html5","tag-html5-charts","tag-infographics","tag-information-graphics","tag-information-visualization","tag-interactive-graphics","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-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-line-chart","tag-line-chart","tag-line-charts","tag-millionaires","tag-multi-line-chart","tag-multi-series-line-chart","tag-statistics","tag-step-line-chart","tag-stepped-line-chart","tag-storytelling-examples","tag-tips-and-tricks","tag-tutorial","tag-visual-analysis","tag-visual-analytics","tag-visual-storytelling-examples","tag-visualization-techniques","tag-visualizations","tag-wealth","tag-web-design","tag-web-developers","tag-web-development","tag-website","tag-website-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>Making Line Chart \u2013 and Step Line Chart \u2013 in JavaScript<\/title>\n<meta name=\"description\" content=\"A line chart is one of the basic, evergreen graphs every data designer &amp; web developer dealing w\/ analytics should know how to make. Here&#039;s 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\/09\/14\/line-chart-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Making Line Chart \u2013 and Step Line Chart \u2013 in JavaScript\" \/>\n<meta property=\"og:description\" content=\"A line chart is a basic graph every data designer &amp; web developer dealing w\/ analytics should know how to make. Here&#039;s the tutorial!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-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=\"2022-09-14T09:00:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-31T14:44:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-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=\"Making Line Chart \u2013 and Step Line Chart \u2013 in JavaScript\" \/>\n<meta name=\"twitter:description\" content=\"A line chart is a basic graph every data designer &amp; web developer dealing w\/ analytics should know how to make. Here&#039;s the tutorial!\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-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=\"12 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\/09\/14\/line-chart-in-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/\"},\"author\":{\"name\":\"Shachee Swadia\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"headline\":\"Making Line Chart \u2014 and Step Line Chart \u2014 in JavaScript\",\"datePublished\":\"2022-09-14T09:00:33+00:00\",\"dateModified\":\"2023-10-31T14:44:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/\"},\"wordCount\":1470,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-chart.png\",\"keywords\":[\"AnyChart\",\"app development\",\"best data visualization examples\",\"billionaires\",\"chart design\",\"chart examples\",\"charts\",\"data analysis\",\"data analytics\",\"data analytics examples\",\"data design\",\"data graphic\",\"data graphics\",\"data visual\",\"data visualisation\",\"Data Visualization\",\"data visualization best practices\",\"data visualization design\",\"data visualization development\",\"data visualization examples\",\"data visualization practice\",\"data visualization techniques\",\"data visualization tutorial\",\"data visualizations\",\"data visuals\",\"data viz examples\",\"dataviz examples\",\"developers\",\"example\",\"Forbes\",\"Forbes Billionaires 2022\",\"freeCodeCamp\",\"front-end development\",\"guest post\",\"HTML\",\"HTML charts\",\"HTML5\",\"html5 charts\",\"infographics\",\"information graphics\",\"information visualization\",\"interactive graphics\",\"JavaScript\",\"javascript chart tutorial\",\"javascript charting\",\"javascript charting api\",\"JavaScript charting features\",\"JavaScript charting library\",\"javascript charts\",\"javascript graph\",\"javascript graphics\",\"JavaScript graphics library\",\"JavaScript library\",\"js chart\",\"js charting\",\"js charts\",\"JS graphics\",\"js line chart\",\"line chart\",\"line charts\",\"millionaires\",\"multi-line chart\",\"multi-series line chart\",\"statistics\",\"step line chart\",\"stepped line chart\",\"storytelling examples\",\"Tips and tricks\",\"tutorial\",\"visual analysis\",\"visual analytics\",\"visual storytelling examples\",\"visualization techniques\",\"visualizations\",\"wealth\",\"web design\",\"web developers\",\"web development\",\"website\",\"website development\"],\"articleSection\":[\"AnyChart Charting Component\",\"HTML5\",\"JavaScript\",\"JavaScript Chart Tutorials\",\"Tips and Tricks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/\",\"name\":\"Making Line Chart \u2013 and Step Line Chart \u2013 in JavaScript\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-chart.png\",\"datePublished\":\"2022-09-14T09:00:33+00:00\",\"dateModified\":\"2023-10-31T14:44:35+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"description\":\"A line chart is one of the basic, evergreen graphs every data designer & web developer dealing w\/ analytics should know how to make. Here's the tutorial!\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-chart.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-chart.png\",\"width\":1800,\"height\":945},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Making Line Chart \u2014 and Step Line Chart \u2014 in 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":"Making Line Chart \u2013 and Step Line Chart \u2013 in JavaScript","description":"A line chart is one of the basic, evergreen graphs every data designer & web developer dealing w\/ analytics should know how to make. Here's 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\/09\/14\/line-chart-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Making Line Chart \u2013 and Step Line Chart \u2013 in JavaScript","og_description":"A line chart is a basic graph every data designer & web developer dealing w\/ analytics should know how to make. Here's the tutorial!","og_url":"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2022-09-14T09:00:33+00:00","article_modified_time":"2023-10-31T14:44:35+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-chart-social.png","type":"","width":"","height":""}],"author":"Shachee Swadia","twitter_card":"summary_large_image","twitter_title":"Making Line Chart \u2013 and Step Line Chart \u2013 in JavaScript","twitter_description":"A line chart is a basic graph every data designer & web developer dealing w\/ analytics should know how to make. Here's the tutorial!","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-chart-social.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Shachee Swadia","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/"},"author":{"name":"Shachee Swadia","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"headline":"Making Line Chart \u2014 and Step Line Chart \u2014 in JavaScript","datePublished":"2022-09-14T09:00:33+00:00","dateModified":"2023-10-31T14:44:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/"},"wordCount":1470,"commentCount":0,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-chart.png","keywords":["AnyChart","app development","best data visualization examples","billionaires","chart design","chart examples","charts","data analysis","data analytics","data analytics examples","data design","data graphic","data graphics","data visual","data visualisation","Data Visualization","data visualization best practices","data visualization design","data visualization development","data visualization examples","data visualization practice","data visualization techniques","data visualization tutorial","data visualizations","data visuals","data viz examples","dataviz examples","developers","example","Forbes","Forbes Billionaires 2022","freeCodeCamp","front-end development","guest post","HTML","HTML charts","HTML5","html5 charts","infographics","information graphics","information visualization","interactive graphics","JavaScript","javascript chart tutorial","javascript charting","javascript charting api","JavaScript charting features","JavaScript charting library","javascript charts","javascript graph","javascript graphics","JavaScript graphics library","JavaScript library","js chart","js charting","js charts","JS graphics","js line chart","line chart","line charts","millionaires","multi-line chart","multi-series line chart","statistics","step line chart","stepped line chart","storytelling examples","Tips and tricks","tutorial","visual analysis","visual analytics","visual storytelling examples","visualization techniques","visualizations","wealth","web design","web developers","web development","website","website development"],"articleSection":["AnyChart Charting Component","HTML5","JavaScript","JavaScript Chart Tutorials","Tips and Tricks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/","url":"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/","name":"Making Line Chart \u2013 and Step Line Chart \u2013 in JavaScript","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-chart.png","datePublished":"2022-09-14T09:00:33+00:00","dateModified":"2023-10-31T14:44:35+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"description":"A line chart is one of the basic, evergreen graphs every data designer & web developer dealing w\/ analytics should know how to make. Here's the tutorial!","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-chart.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/09\/line-chart.png","width":1800,"height":945},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2022\/09\/14\/line-chart-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Making Line Chart \u2014 and Step Line Chart \u2014 in 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\/15672","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=15672"}],"version-history":[{"count":21,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/15672\/revisions"}],"predecessor-version":[{"id":16969,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/15672\/revisions\/16969"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=15672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=15672"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=15672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}