{"id":13147,"date":"2021-07-28T11:31:35","date_gmt":"2021-07-28T11:31:35","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=13147"},"modified":"2022-09-12T16:44:59","modified_gmt":"2022-09-12T16:44:59","slug":"line-chart-js","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/","title":{"rendered":"How to Create Line Chart with JavaScript"},"content":{"rendered":"<p><a href=\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/\"><img decoding=\"async\" class=\"alignnone size-full wp-image-13202\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js.png\" alt=\"A JavaScript-based multi-series line chart on a laptop screen\" width=\"100%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js.png 1366w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js-300x169.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js-768x432.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js-1024x576.png 1024w\" sizes=\"(max-width: 1366px) 100vw, 1366px\" \/><\/a>A <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/line-chart\/\">line chart<\/a> is one of the basic and\u00a0most commonly used techniques of\u00a0<a href=\"https:\/\/www.anychart.com\/blog\/2018\/11\/20\/data-visualization-definition-history-examples\/\">data visualization<\/a>. Such graphics are known to provide an informative look at the change of one or several variables over time. Right now, I&#8217;ll explain how to easily create\u00a0a cool interactive line chart\u00a0using\u00a0JavaScript!\u00a0The process will be demonstrated with the help of compelling examples that you can play with afterwards to hone your new data visualization development skills.<\/p>\n<p>To make the article especially\u00a0thrilling for you to read and learn from, I decided to showcase a practical application of a line chart to real-world data. The month of June was celebrated as <a href=\"https:\/\/en.wikipedia.org\/wiki\/Gay_pride#LGBT_Pride_Month\" target=\"_blank\" rel=\"nofollow\">Pride Month<\/a>, and I thought it would be great to see how attitudes toward LGBT people have changed over the recent years. Then I found interesting public opinion data from the\u00a0General Social Survey (GSS), a project of the National Opinion Research Center (NORC) at the University of Chicago, which appeared to be a good fit, and took part of it to visualize in this guide.<\/p>\n<p>So, follow along with the tutorial and you will also\u00a0be able to explore\u00a0the shifts in acceptance of same-sex relationships in the United States over the last two decades! We will create a single-series JS line chart first, representing the general trend, and then a multi-series JS line chart to visualize a breakdown by age group.<\/p>\n<p>All aboard!<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2>JS Line Chart Preview<\/h2>\n<p>Before we begin, check out a preview! Here is a look at the beautiful line chart that we will have built with JavaScript by\u00a0the end of this data visualization tutorial.\u00a0Plus, it will be interactive and easily embeddable in any web page or app!<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-13156\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js-preview.png\" alt=\"The final interactive JS line chart to be build by the end of this tutorial for web developers and data designers\" width=\"100%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js-preview.png 1170w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js-preview-300x168.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js-preview-768x431.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js-preview-1024x575.png 1024w\" sizes=\"(max-width: 1170px) 100vw, 1170px\" \/><\/p>\n<p>Doesn\u2019t it feel great to look at this colorful chart and feel positive about the future outlook?<\/p>\n<p>Read this step-by-step tutorial all the way to the end and you will learn how to produce such a line graph easily with very little coding.<\/p>\n<h2>Building Basic JavaScript Line Chart in 4 Simple Steps<\/h2>\n<p>The normal order of visualizing data in JavaScript charts\u00a0can be broken down into four basic\u00a0steps, and building a JS line chart follows the same pattern:<\/p>\n<ol>\n<li>Creating a basic HTML page to display the chart.<\/li>\n<li>Including all the JS scripts we need.<\/li>\n<li>Adding the data for the chart.<\/li>\n<li>Writing the JS charting code.<\/li>\n<\/ol>\n<p>So now, let\u2019s dig into each of these steps to draw our line chart in a jiffy.<\/p>\n<h3>1. Creating a basic HTML page<\/h3>\n<p>To start, we create a basic HTML page with a <code>&lt;div&gt;<\/code> block element for our line chart. To\u00a0reference this block element later in the code, we give it an id attribute like \u201ccontainer\u201d.<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Line Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0  html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0  width: 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>Here, we provide the <code>&lt;div&gt;<\/code> with the 100% width and height to render the line chart on the full screen. But it\u2019s not necessary and can be customized according to your requirements, of course.<\/p>\n<h3>2. Including all the JS scripts<\/h3>\n<p>The second step is to reference all the necessary scripts to build the JS line chart. These scripts will go in the <code>&lt;script&gt;<\/code> tag inside of the <code>&lt;head&gt;<\/code> section.<\/p>\n<p>In\u00a0this tutorial, the line chart is built with <a href=\"https:\/\/www.anychart.com\/\">AnyChart<\/a>. It\u00a0is a lightweight and flexible JavaScript (HTML5) charting library with detailed <a href=\"https:\/\/docs.anychart.com\/\" target=\"_blank\" rel=\"nofollow\">documentation<\/a>\u00a0and <a href=\"https:\/\/api.anychart.com\" target=\"_blank\" rel=\"nofollow\">API reference<\/a>. In addition,\u00a0there are a lot of\u00a0<a href=\"https:\/\/www.anychart.com\/products\/anychart\/gallery\/\">chart examples<\/a>\u00a0to check out and use as the starting point, as well as a utility called\u00a0<a href=\"https:\/\/playground.anychart.com\/\" target=\"_blank\" rel=\"nofollow\">Playground<\/a>\u00a0to experiment with the code.<\/p>\n<p>Since the line chart is one of the basic chart types,\u00a0it requires only the <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#base\" target=\"_blank\" rel=\"nofollow\">base<\/a> module of AnyChart. We can easily obtain it from the <a href=\"https:\/\/cdn.anychart.com\" target=\"_blank\" rel=\"nofollow\">CDN<\/a>. The JS line chart code itself will be written in the <code>&lt;script&gt;<\/code> tag inside of the <code>&lt;body&gt;<\/code> section.<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Line Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.10.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  html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0  width: 100%; height: 100%; margin: 0; padding: 0; \r\n\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 line 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;\r\n<\/code><\/pre>\n<h3>3. Adding the data<\/h3>\n<p>In this tutorial, we will be visualizing\u00a0data from\u00a0the <a href=\"https:\/\/gssdataexplorer.norc.org\/trends\/Gender%20&amp;%20Marriage?measure=homosex\" target=\"_blank\" rel=\"nofollow\">GSS\u00a0Data Explorer<\/a>,\u00a0namely the data that shows\u00a0how the breakdown of responses to the question &#8220;Is it wrong for same-sex adults to have sexual relations?&#8221; changed over time between 1990 and 2018.\u00a0Namely, we&#8217;ll represent the percentage of responses &#8220;Not wrong at all&#8221; that looks like a\u00a0good indicator of\u00a0acceptance here.<\/p>\n<p>AnyChart supports\u00a0<a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Supported_Data_Formats\" target=\"_blank\" rel=\"nofollow\">multiple options to load data<\/a> to charts. The data set for our line chart is pretty straightforward\u00a0and not large at all.\u00a0So we can simply include it inside the code itself.<\/p>\n<p>To do that, we create a function that will return the data to\u00a0keep it as a separate block of code.<\/p>\n<pre><code class=\"javascript\">function getData() {\r\n  return [\r\n    ['1990',12],\r\n    ['1991',14],\r\n    ['1993',21],\r\n    ['1994',21],\r\n    ['1996',26],\r\n    ['1998',26],\r\n    ['2000',27],\r\n    ['2002',31],\r\n    ['2004',29],\r\n    ['2006',31],\r\n    ['2008',36],\r\n    ['2010',41],\r\n    ['2012',42],\r\n    ['2014',48],\r\n    ['2016',50],\r\n    ['2018',57]\r\n  ];\r\n}<\/code><\/pre>\n<p>All the prep is done and now it\u2019s time to create the line chart with a few lines of JavaScript code!<\/p>\n<h3>4. Writing the JS line charting code<\/h3>\n<p>Before anything else, we add a function enclosing all the JavaScript code needed to create the intended interactive line chart. This ensures that the code inside it will only execute once the page is all loaded.<\/p>\n<p>We set up the data by calling the function we made in the previous step, and then we map the data to indicate that the first parameter for every data point is the\u00a0X value and the second parameter is the\u00a0Y value. Next, we call the <code>line()<\/code> function to create the JS line chart.<\/p>\n<pre><code class=\"javascript\">\/\/ create a data set on our data\r\nvar dataSet = anychart.data.set(getData());\r\n\r\n\/\/ map data for the line chart,\r\n\/\/ take x from the zero column and value from the first column\r\nvar seriesData = dataSet.mapAs({ x: 0, value: 1 });\r\n\r\n\/\/ create a line chart\r\nvar chart = anychart.line();<\/code><\/pre>\n<p>Now, we set the titles\u00a0for the line chart and for the Y-axis.<\/p>\n<pre><code class=\"javascript\">\/\/ configure the chart title text settings\r\nchart.title('Acceptance of same-sex relationships in the US over the last 2 decades');\r\n\r\n\/\/ set the y axis title\r\nchart.yAxis().title('% of people who accept same-sex relationships');<\/code><\/pre>\n<p>Lastly, we\u00a0load the mapped data to the line chart, set the container id, and draw the graphic.<\/p>\n<pre><code class=\"javascript\">\/\/ create a line series with the mapped data\r\nvar lineChart = chart.line(seriesData);\r\n\r\n\/\/ set the container id for the line chart\r\nchart.container('container');\r\n\r\n\/\/ draw the line chart\r\nchart.draw();<\/code><\/pre>\n<p>Voil\u00e0! A functional, interactive, JavaScript-based line chart is created! This was quite\u00a0quick and simple, wasn&#8217;t it?<\/p>\n<p><strong>Check out the result below, and you are more than welcome to see this chart and play with its code on\u00a0<a href=\"https:\/\/playground.anychart.com\/AMYKy0zt\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>.<\/strong><\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-AMYKy0zt\" src=\"https:\/\/playground.anychart.com\/AMYKy0zt\/iframe\" width=\"300\" height=\"150\" frameborder=\"0\" sandbox=\"allow-scripts allow-pointer-lock allow-same-origin allow-popups allow-modals allow-forms\" allowfullscreen=\"allowfullscreen\"><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-AMYKy0zt{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>What does this line chart tell us? We can clearly see the positive change over time and how the acceptance of same-sex relationships in the United States\u00a0was gradually increasing between 1990 and 2018 with just a few slight pauses.<\/p>\n<p>But do not leave yet!\u00a0Although this chart already looks good, it is just a very basic version of the JS line chart we can afford to obtain. It will only take a few more steps to\u00a0add functionality and interactivity.<\/p>\n<p>Now, get ready to make a stunning multi-line chart that will visualize a breakdown by age!<\/p>\n<h2>Creating Interactive Multi-Series JS Line Chart<\/h2>\n<p>When there is segregated data, we use a multi-series line chart to indicate each segment as a separate line. Let&#8217;s see how it is done!<\/p>\n<p>The basic code remains the same. But instead of\u00a0one series, we will create multiple series. Of course, the data will contain multiple data points for each year now as we break down the total percentage for &#8220;Not wrong at all&#8221; by age groups: 18-34, 35-49, 50-64, and 65+.<\/p>\n<pre><code class=\"javascript\">function getData() {\r\n  return [\r\n    ['1990',16.9,12.2,10.2,5.2],\r\n    ['1991',17,17.8,10,4.8],\r\n    ['1993',26.5,23.8,16.8,6.6],\r\n    ['1994',28.7,22,17.3,9.1],\r\n    ['1996',35.7,24,22.6,9.2],\r\n    ['1998',37.2,24.6,22.4,11.2],\r\n    ['2000',36.5,26.2,23.7,9.9],\r\n    ['2002',40,34.4,23.8,16.4],\r\n    ['2004',33.3,28.8,32.5,14.3],\r\n    ['2006',40.2,32.1,27.5,15.1],\r\n    ['2008',49.3,37.2,31.4,17.1],\r\n    ['2010',51.9,42.5,36.1,28.5],\r\n    ['2012',53.1,43.8,36,24.6],\r\n    ['2014',63.7,45.9,44.7,31.3],\r\n    ['2016',66.3,52,42.3,37.2],\r\n    ['2018',70.1,57.7,49.2,39]\r\n  ];\r\n}<\/code><\/pre>\n<p>We will need to create a different data mapping for each series.<\/p>\n<pre><code class=\"javascript\">\/\/ map data for the first series,\r\n\/\/ take x from the zero column and value from the first column\r\nvar firstSeriesData = dataSet.mapAs({ x: 0, value: 1 });\r\n\r\n\/\/ map data for the second series,\r\n\/\/ take x from the zero column and value from the second column\r\nvar secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });\r\n\r\n\/\/ map data for the third series,\r\n\/\/ take x from the zero column and value from the third column\r\nvar thirdSeriesData = dataSet.mapAs({ x: 0, value: 3 });\r\n  \r\n\/\/ map data for the fourth series,\r\n\/\/ take x from the zero column and value from the fourth column\r\nvar fourthSeriesData = dataSet.mapAs({ x: 0, value: 4 });<\/code><\/pre>\n<p>We then link each of those series to a different line and name each series based on the segments.<\/p>\n<pre><code class=\"javascript\">\/\/ create the first series with the mapped data\r\nvar firstSeries = chart.line(firstSeriesData);\r\nfirstSeries.name('18-34');\r\n\r\n\/\/ create the second series with the mapped data\r\nvar secondSeries = chart.line(secondSeriesData);\r\nsecondSeries.name('35-49');\r\n\r\n\/\/ create the third series with the mapped data\r\nvar thirdSeries = chart.line(thirdSeriesData);\r\nthirdSeries.name('50-64');\r\n  \r\n\/\/ create the fourth series with the mapped data\r\nvar fourthSeries = chart.line(fourthSeriesData);\r\nfourthSeries.name('65+');<\/code><\/pre>\n<p>Here, since we have multiple\u00a0lines depicted in our JS line plot, we need a legend that will help identify which line represents what segment. Don\u2019t worry, it\u2019s nothing complex. The chart legend is automatically created by the JS library and we just need to turn it on.<\/p>\n<pre><code class=\"javascript\">\/\/ turn the legend on\r\nchart.legend().enabled(true);<\/code><\/pre>\n<p><strong>That\u2019s it! With these simple modifications, we get a lovely-looking multi-series line chart built with JavaScript! It\u00a0can\u00a0also be viewed and further played with on\u00a0<a href=\"https:\/\/playground.anychart.com\/1tvaNdD6\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>.<\/strong><\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-1tvaNdD6\" src=\"https:\/\/playground.anychart.com\/1tvaNdD6\/iframe\" width=\"300\" height=\"150\" frameborder=\"0\" sandbox=\"allow-scripts allow-pointer-lock allow-same-origin allow-popups allow-modals allow-forms\" allowfullscreen=\"allowfullscreen\"><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-1tvaNdD6{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>Again, we can distinctly grasp how the overall trend is positive in all age groups, especially in the younger generation.<\/p>\n<h2>Customizing Multi-Series JS Line Chart Design<\/h2>\n<p>The multi-series line chart looks great as is, but we can make it even more awesome with some customizations! AnyChart is great in that respect because it offers a whole lot of\u00a0out-of-the-box options\u00a0allowing you to modify the JS (HTML5) charts like this with ease.<\/p>\n<p>So, let\u2019s make some quick\u00a0tweaks to have a more insightful view of the data.<\/p>\n<h3>1. Smoothening the lines<\/h3>\n<p>As we can see, the lines formed currently are sharp at the connections and give a more geometric feel. In the AnyChart JS library, we can\u00a0get smoother lines by simply substituting &#8220;line&#8221;\u00a0with &#8220;spline&#8221; when linking the data with the series.<\/p>\n<pre><code class=\"javascript\">\/\/ create the first series with the mapped data\r\nvar firstSeries = chart.spline(firstSeriesData);\r\nfirstSeries.name('18-34');\r\n\r\n\/\/ create the second series with the mapped data\r\nvar secondSeries = chart.spline(secondSeriesData);\r\nsecondSeries.name('35-49');\r\n\r\n\/\/ create the third series with the mapped data\r\nvar thirdSeries = chart.spline(thirdSeriesData);\r\nthirdSeries.name('50-64');\r\n  \r\n\/\/ create the fourth series with the mapped data\r\nvar fourthSeries = chart.spline(fourthSeriesData);\r\nfourthSeries.name('65+');<\/code><\/pre>\n<p>After these simple changes,\u00a0our\u00a0line chart becomes a\u00a0<a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/spline-chart\/\">spline chart<\/a>!<\/p>\n<h3>2. Adding crosshair on hover for each data point<\/h3>\n<p>Since the lines in our visualization are now smooth, making\u00a0crosshairs show up when the viewer hovers over the lines can\u00a0improve readability. It is also easy to customize\u00a0the crosshair behavior. In this case, for example, let&#8217;s keep\u00a0only the X-axis connector and label.<\/p>\n<pre><code class=\"javascript\">\/\/ turn on the crosshair\r\nchart.crosshair().enabled(true).yLabel(false).yStroke(null);<\/code><\/pre>\n<p><strong>Check out the interactive JavaScript spline chart with the crosshair! It is available on <a href=\"https:\/\/playground.anychart.com\/7l7UhiWw\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>.<\/strong><\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-7l7UhiWw\" src=\"https:\/\/playground.anychart.com\/7l7UhiWw\/iframe\" width=\"300\" height=\"150\" frameborder=\"0\" sandbox=\"allow-scripts allow-pointer-lock allow-same-origin allow-popups allow-modals allow-forms\" allowfullscreen=\"allowfullscreen\"><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-7l7UhiWw{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>Ultimately, for the final chart of this JS line chart tutorial, let\u2019s go ahead with straight lines instead of smooth curves. But we&#8217;ll keep the crosshair anyway.<\/p>\n<h3>3. Improving the JS line chart tooltip<\/h3>\n<p>To make the line chart tooltip more informative, we make\u00a0it\u00a0display that the numbers are percentage values and the segments are age groups.<\/p>\n<p>This can be simply done by setting the <code>format()<\/code> function for the tooltip in each line series.\u00a0Here&#8217;s an example for the first one:<\/p>\n<pre><code class=\"javascript\">firstSeries\r\n  .tooltip()\r\n  .format(\"Age group 18-34 : {%value}%\");<\/code><\/pre>\n<h3>4. Changing the colors and other aesthetics<\/h3>\n<p>Since this JavaScript-based line chart talks about same-sex relationships, we can use pride colors to represent the lines. This makes the chart look more personalized and represents the topic better.<\/p>\n<p>Let\u2019s also make the lines a bit thicker\u00a0so they look more pronounced. Modifying the color and the line width can be done together using the <code>stroke<\/code> attribute in the settings of each series. Like this:<\/p>\n<pre><code class=\"javascript\">firstSeries\r\n  .stroke('3 #f49595')<\/code><\/pre>\n<p>Lastly, we add a simple animation to jazz up the line chart, which is again done very easily as the JavaScript library has it as a pre-built feature.<\/p>\n<pre><code class=\"javascript\">\/\/ turn on the line chart animation\r\nchart.animation(true);<\/code><\/pre>\n<p>It\u2019s done! A stunning, interactive JavaScript line chart is all wrapped up!<\/p>\n<p><strong>For your convenience, the final HTML\/CSS\/JS line chart code is below the visualization. Don&#8217;t hesitate to check it out on <a href=\"https:\/\/playground.anychart.com\/4L1XeREM\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground <\/a>and maybe apply your data and other changes.<\/strong><\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-4L1XeREM\" src=\"https:\/\/playground.anychart.com\/4L1XeREM\/iframe\" width=\"300\" height=\"150\" frameborder=\"0\" sandbox=\"allow-scripts allow-pointer-lock allow-same-origin allow-popups allow-modals allow-forms\" allowfullscreen=\"allowfullscreen\"><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-4L1XeREM{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<pre><code>&lt;html&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Line Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.10.0\/js\/anychart-base.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; height: 100%; margin: 0; padding: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/style&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;body&gt;  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;script&gt;\r\n\r\nanychart.onDocumentReady(function () {\r\n\r\n\u00a0\u00a0\/\/ create a data set on our data\r\n\u00a0\u00a0var dataSet = anychart.data.set(getData());\r\n  \r\n\u00a0\u00a0\/\/ map data for the first series,\r\n  \/\/ take x from the zero column and value from the first column\r\n\u00a0\u00a0var firstSeriesData = dataSet.mapAs({ x: 0, value: 1 });\r\n\r\n\u00a0\u00a0\/\/ map data for the second series,\r\n  \/\/ take x from the zero column and value from the second column\r\n\u00a0\u00a0var secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });\r\n \r\n  \/\/ map data for the third series,\r\n  \/\/ take x from the zero column and value from the third column \r\n\u00a0\u00a0var thirdSeriesData = dataSet.mapAs({ x: 0, value: 3 });\r\n  \r\n\u00a0\u00a0\/\/ map data for the fourth series,\r\n  \/\/ take x from the zero column and value from the fourth column\r\n\u00a0\u00a0var fourthSeriesData = dataSet.mapAs({ x: 0, value: 4 });\r\n\r\n\u00a0\u00a0\/\/ create a line chart\r\n\u00a0\u00a0var chart = anychart.line();\r\n\r\n\u00a0\u00a0\/\/ turn on the line chart animation\r\n\u00a0\u00a0chart.animation(true);\r\n  \r\n\u00a0\u00a0\/\/ configure the chart title text settings\r\n\u00a0\u00a0chart.title('Acceptance of same-sex relationships in the US over the last 2 decades');\r\n\r\n\u00a0\u00a0\/\/ set the y axis title\r\n\u00a0\u00a0chart.yAxis().title('% of people who accept same-sex relationships');\r\n  \r\n\u00a0\u00a0\/\/ turn on the crosshair\r\n\u00a0\u00a0chart.crosshair().enabled(true).yLabel(false).yStroke(null);\r\n\r\n\u00a0\u00a0\/\/ create the first series with the mapped data\r\n\u00a0\u00a0var firstSeries = chart.line(firstSeriesData);\r\n\u00a0\u00a0firstSeries\r\n  \u00a0\u00a0.name('18-34')\r\n\u00a0\u00a0\u00a0\u00a0.stroke('3 #f49595')\r\n\u00a0\u00a0\u00a0\u00a0.tooltip()\r\n\u00a0\u00a0\u00a0\u00a0.format(\"Age group 18-34 : {%value}%\");\r\n  \r\n\u00a0\u00a0\/\/ create the second series with the mapped data\r\n\u00a0\u00a0var secondSeries = chart.line(secondSeriesData);\r\n\u00a0\u00a0secondSeries\r\n\u00a0\u00a0\u00a0\u00a0.name('35-49')\r\n\u00a0\u00a0\u00a0\u00a0.stroke('3 #f9eb97')\r\n\u00a0\u00a0\u00a0\u00a0.tooltip()\r\n\u00a0\u00a0\u00a0\u00a0.format(\"Age group 35-49 : {%value}%\");\r\n\r\n\u00a0\u00a0\/\/ create the third series with the mapped data\r\n\u00a0\u00a0var thirdSeries = chart.line(thirdSeriesData);\r\n\u00a0\u00a0thirdSeries\r\n\u00a0\u00a0\u00a0\u00a0.name('50-64')\r\n\u00a0\u00a0\u00a0\u00a0.stroke('3 #a8d9f6')\r\n\u00a0\u00a0\u00a0\u00a0.tooltip()\r\n\u00a0\u00a0\u00a0\u00a0.format(\"Age group 50-64 : {%value}%\");\r\n  \r\n\u00a0\u00a0\/\/ create the fourth series with the mapped data\r\n\u00a0\u00a0var fourthSeries = chart.line(fourthSeriesData);\r\n\u00a0\u00a0fourthSeries\r\n  \u00a0\u00a0.name('65+')\r\n\u00a0\u00a0\u00a0\u00a0.stroke('3 #e2bbfd')\r\n\u00a0\u00a0\u00a0\u00a0.tooltip()\r\n\u00a0\u00a0\u00a0\u00a0.format(\"Age group 65+ : {%value}%\");\r\n\r\n\u00a0\u00a0\/\/ turn the legend on\r\n\u00a0\u00a0chart.legend().enabled(true);\r\n\r\n\u00a0\u00a0\/\/ set the container id for the line chart\r\n\u00a0\u00a0chart.container('container');\r\n  \r\n\u00a0\u00a0\/\/ draw the line chart\r\n\u00a0\u00a0chart.draw();\r\n\r\n});\r\n\r\nfunction getData() {\r\n  return [\r\n    ['1990',16.9,12.2,10.2,5.2],\r\n    ['1991',17,17.8,10,4.8],\r\n    ['1993',26.5,23.8,16.8,6.6],\r\n    ['1994',28.7,22,17.3,9.1],\r\n    ['1996',35.7,24,22.6,9.2],\r\n    ['1998',37.2,24.6,22.4,11.2],\r\n    ['2000',36.5,26.2,23.7,9.9],\r\n    ['2002',40,34.4,23.8,16.4],\r\n    ['2004',33.3,28.8,32.5,14.3],\r\n    ['2006',40.2,32.1,27.5,15.1],\r\n    ['2008',49.3,37.2,31.4,17.1],\r\n    ['2010',51.9,42.5,36.1,28.5],\r\n    ['2012',53.1,43.8,36,24.6],\r\n    ['2014',63.7,45.9,44.7,31.3],\r\n    ['2016',66.3,52,42.3,37.2],\r\n    ['2018',70.1,57.7,49.2,39]\r\n\u00a0\u00a0];\r\n}<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>A line chart is a very functional and practical form of data visualization. It is used rather often. So I thought you would love to know how to create a line chart hassle-free.\u00a0Using a JavaScript charting library like AnyChart is a convenient way to not only quickly create both good-looking and informative line charts but also add some customizations to tailor\u00a0the visualization to suit your specific needs in a\u00a0pretty straightforward\u00a0manner.<\/p>\n<p>For a\u00a0deeper look at how to build and personalize JS line charts, see the <a href=\"https:\/\/docs.anychart.com\/Basic_Charts\/Line_Chart\" target=\"_blank\" rel=\"nofollow\">line chart documentation<\/a>. Also, don&#8217;t miss out on checking out these<a href=\"https:\/\/www.anychart.com\/products\/anychart\/gallery\/Line_Charts\/\">line chart examples<\/a> for inspiration.<\/p>\n<p>If you have any questions about the JavaScript line charts built in this tutorial, or the <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/line-chart\/\">line chart type<\/a> in general, or any specific features you are not sure how to implement, please leave them in the comments and I will do my best to\u00a0provide timely responses.<\/p>\n<p>Let us all be proud of who we are and add this chart into\u00a0the data visualization development skillset to flaunt!<\/p>\n<hr \/>\n<p><strong><em>The team of AnyChart\u00a0thanks\u00a0Shachee Swadia, a freelance data designer, for contributing\u00a0this\u00a0excellent JS Line Chart tutorial.<\/em><\/strong><\/p>\n<hr \/>\n<p><strong><em><a href=\"https:\/\/www.anychart.com\/support\/\">Contact us<\/a> if you\u00a0want to create a cool guest post for our blog.<\/em><\/strong><\/p>\n<hr \/>\n<p><em><strong>Check out\u00a0other <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JavaScript charting tutorials<\/a>.<\/strong><\/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>A line chart is one of the basic and\u00a0most commonly used techniques of\u00a0data visualization. Such graphics are known to provide an informative look at the change of one or several variables over time. Right now, I&#8217;ll explain how to easily create\u00a0a cool interactive line chart\u00a0using\u00a0JavaScript!\u00a0The process will be demonstrated with the help of compelling examples [&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,263,8,23,13,279,4],"tags":[843,53,260,265,254,1758,284,283,127,166,258,282,471,266,620,916,1292,880,806,1759,509,1098,195,294,257,2220,54,461,1389,1760,256,1111,350,842,744,1379,844,165,313,1370,133,774,775,1978,805,2694,91,2696,2013,2014,32,55,1335,144,167,146,433,152,151,36,907,141,249,81,57,1238,142,96,99,134,58,65,56,101,2684,2688,2689,2690,196,106,1509,2686,2693,2695,1730,423,1729,2691,2692,2685,2687,459,1310,782,1331,30,172,309,493,1625,807,808,832,954,1301,293,745,899,2015,1763,804],"class_list":["post-13147","post","type-post","status-publish","format-standard","hentry","category-anychart-charting-component","category-big-data","category-business-intelligence","category-html5","category-javascript","category-javascript-chart-tutorials","category-tips-and-tricks","tag-advanced-data-visualization","tag-anychart","tag-best-data-visualization-examples","tag-big-data","tag-chart","tag-chart-design","tag-chart-examples","tag-chart-title","tag-chart-types","tag-charting","tag-charts","tag-data","tag-data-analysis","tag-data-analytics","tag-data-analytics-examples","tag-data-api","tag-data-chart","tag-data-charting","tag-data-charts","tag-data-design","tag-data-graphics","tag-data-is-beautiful","tag-data-over-time","tag-data-science","tag-data-stories","tag-data-visual","tag-data-visualization","tag-data-visualization-101","tag-data-visualization-best-pracices","tag-data-visualization-design","tag-data-visualization-examples","tag-data-visualization-practice","tag-data-visualization-projects","tag-data-visualization-task","tag-data-visualization-techniques","tag-data-visualization-tool","tag-data-visualization-tutorial","tag-data-visualizations","tag-data-visuals","tag-data-viz-examples","tag-dataviz","tag-dataviz-examples","tag-dataviz-projects","tag-datetime-charts","tag-front-end-development","tag-general-social-survey","tag-graphics","tag-gss","tag-html","tag-html-charts","tag-html5","tag-html5-charts","tag-infographic","tag-infographics","tag-interactive-charts","tag-interactive-data-visualization","tag-interactive-graphics","tag-interactive-infographic","tag-interactive-visualizations","tag-javascript","tag-javascript-chart-tutorial","tag-javascript-charting","tag-javascript-charting-api","tag-javascript-charting-library","tag-javascript-charts","tag-javascript-graph","tag-javascript-graphics","tag-javascript-graphics-library","tag-javascript-library","tag-javascript-technologies","tag-js-chart","tag-js-charting","tag-js-charts","tag-js-graphics","tag-js-line-chart","tag-js-spline-chart","tag-lgbt","tag-lgbtq","tag-line-chart","tag-line-charts","tag-multi-line-chart","tag-multi-series-line-chart","tag-national-opinion-research-center","tag-norc","tag-polling","tag-polling-data","tag-polls","tag-pride-month","tag-same-sex-relationships","tag-single-series-line-chart","tag-spline-chart","tag-statistics","tag-survey","tag-survey-data","tag-survey-data-visualization","tag-tips-and-tricks","tag-tutorial","tag-united-states","tag-university-of-chicago","tag-visual","tag-visual-analysis","tag-visual-analytics","tag-visual-data","tag-visual-data-analytics","tag-visual-presentation","tag-visualization","tag-visualization-techniques","tag-visualizations","tag-web-charts","tag-web-developers","tag-web-development","wpautop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Line Chart | Learn How to Create Line Chart with JavaScript<\/title>\n<meta name=\"description\" content=\"A line chart is one of the basic and most popular data visualization techniques. Learn how to easily build beautiful and informative JS line chart graphics.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Line Chart with JavaScript\" \/>\n<meta property=\"og:description\" content=\"A line chart is one of the basic and most common data visualization techniques. Learn how to build compelling JS line charts with ease.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-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=\"2021-07-28T11:31:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-12T16:44:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-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=\"How to Create Line Chart with JavaScript\" \/>\n<meta name=\"twitter:description\" content=\"A line chart is one of the basic and most common data visualization techniques. Learn how to build compelling JS line charts with ease.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-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=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/\"},\"author\":{\"name\":\"Shachee Swadia\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"headline\":\"How to Create Line Chart with JavaScript\",\"datePublished\":\"2021-07-28T11:31:35+00:00\",\"dateModified\":\"2022-09-12T16:44:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/\"},\"wordCount\":1869,\"commentCount\":2,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js.png\",\"keywords\":[\"advanced data visualization\",\"AnyChart\",\"best data visualization examples\",\"big data\",\"chart\",\"chart design\",\"chart examples\",\"chart title\",\"chart types\",\"charting\",\"charts\",\"data\",\"data analysis\",\"data analytics\",\"data analytics examples\",\"data API\",\"data chart\",\"data charting\",\"data charts\",\"data design\",\"data graphics\",\"data is beautiful\",\"data over time\",\"data science\",\"data stories\",\"data visual\",\"Data Visualization\",\"data visualization 101\",\"data visualization best practices\",\"data visualization design\",\"data visualization examples\",\"data visualization practice\",\"data visualization projects\",\"data visualization task\",\"data visualization techniques\",\"data visualization tool\",\"data visualization tutorial\",\"data visualizations\",\"data visuals\",\"data viz examples\",\"dataviz\",\"dataviz examples\",\"dataviz projects\",\"date\/time charts\",\"front-end development\",\"General Social Survey\",\"graphics\",\"GSS\",\"HTML\",\"HTML charts\",\"HTML5\",\"html5 charts\",\"infographic\",\"infographics\",\"interactive charts\",\"interactive data visualization\",\"interactive graphics\",\"interactive infographic\",\"interactive visualizations\",\"JavaScript\",\"javascript chart tutorial\",\"javascript charting\",\"javascript charting api\",\"JavaScript charting library\",\"javascript charts\",\"javascript graph\",\"javascript graphics\",\"JavaScript graphics library\",\"JavaScript library\",\"javascript technologies\",\"js chart\",\"js charting\",\"js charts\",\"JS graphics\",\"js line chart\",\"js spline chart\",\"LGBT\",\"LGBTQ\",\"line chart\",\"line charts\",\"multi-line chart\",\"multi-series line chart\",\"National Opinion Research Center\",\"NORC\",\"polling\",\"polling data\",\"polls\",\"Pride Month\",\"same-sex relationships\",\"single-series line chart\",\"spline chart\",\"statistics\",\"survey\",\"survey data\",\"survey data visualization\",\"Tips and tricks\",\"tutorial\",\"united states\",\"University of Chicago\",\"visual\",\"visual analysis\",\"visual analytics\",\"visual data\",\"visual data analytics\",\"visual presentation\",\"visualization\",\"visualization techniques\",\"visualizations\",\"web charts\",\"web developers\",\"web development\"],\"articleSection\":[\"AnyChart Charting Component\",\"Big Data\",\"Business Intelligence\",\"HTML5\",\"JavaScript\",\"JavaScript Chart Tutorials\",\"Tips and Tricks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/\",\"name\":\"Line Chart | Learn How to Create Line Chart with JavaScript\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js.png\",\"datePublished\":\"2021-07-28T11:31:35+00:00\",\"dateModified\":\"2022-09-12T16:44:59+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"description\":\"A line chart is one of the basic and most popular data visualization techniques. Learn how to easily build beautiful and informative JS line chart graphics.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js.png\",\"width\":1366,\"height\":768},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create Line 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":"Line Chart | Learn How to Create Line Chart with JavaScript","description":"A line chart is one of the basic and most popular data visualization techniques. Learn how to easily build beautiful and informative JS line chart graphics.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Line Chart with JavaScript","og_description":"A line chart is one of the basic and most common data visualization techniques. Learn how to build compelling JS line charts with ease.","og_url":"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2021-07-28T11:31:35+00:00","article_modified_time":"2022-09-12T16:44:59+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js-social.png","type":"","width":"","height":""}],"author":"Shachee Swadia","twitter_card":"summary_large_image","twitter_title":"How to Create Line Chart with JavaScript","twitter_description":"A line chart is one of the basic and most common data visualization techniques. Learn how to build compelling JS line charts with ease.","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js-social.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Shachee Swadia","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/"},"author":{"name":"Shachee Swadia","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"headline":"How to Create Line Chart with JavaScript","datePublished":"2021-07-28T11:31:35+00:00","dateModified":"2022-09-12T16:44:59+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/"},"wordCount":1869,"commentCount":2,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js.png","keywords":["advanced data visualization","AnyChart","best data visualization examples","big data","chart","chart design","chart examples","chart title","chart types","charting","charts","data","data analysis","data analytics","data analytics examples","data API","data chart","data charting","data charts","data design","data graphics","data is beautiful","data over time","data science","data stories","data visual","Data Visualization","data visualization 101","data visualization best practices","data visualization design","data visualization examples","data visualization practice","data visualization projects","data visualization task","data visualization techniques","data visualization tool","data visualization tutorial","data visualizations","data visuals","data viz examples","dataviz","dataviz examples","dataviz projects","date\/time charts","front-end development","General Social Survey","graphics","GSS","HTML","HTML charts","HTML5","html5 charts","infographic","infographics","interactive charts","interactive data visualization","interactive graphics","interactive infographic","interactive visualizations","JavaScript","javascript chart tutorial","javascript charting","javascript charting api","JavaScript charting library","javascript charts","javascript graph","javascript graphics","JavaScript graphics library","JavaScript library","javascript technologies","js chart","js charting","js charts","JS graphics","js line chart","js spline chart","LGBT","LGBTQ","line chart","line charts","multi-line chart","multi-series line chart","National Opinion Research Center","NORC","polling","polling data","polls","Pride Month","same-sex relationships","single-series line chart","spline chart","statistics","survey","survey data","survey data visualization","Tips and tricks","tutorial","united states","University of Chicago","visual","visual analysis","visual analytics","visual data","visual data analytics","visual presentation","visualization","visualization techniques","visualizations","web charts","web developers","web development"],"articleSection":["AnyChart Charting Component","Big Data","Business Intelligence","HTML5","JavaScript","JavaScript Chart Tutorials","Tips and Tricks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/","url":"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/","name":"Line Chart | Learn How to Create Line Chart with JavaScript","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js.png","datePublished":"2021-07-28T11:31:35+00:00","dateModified":"2022-09-12T16:44:59+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"description":"A line chart is one of the basic and most popular data visualization techniques. Learn how to easily build beautiful and informative JS line chart graphics.","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/07\/line-chart-js.png","width":1366,"height":768},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create Line 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\/13147","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=13147"}],"version-history":[{"count":68,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/13147\/revisions"}],"predecessor-version":[{"id":15513,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/13147\/revisions\/15513"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=13147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=13147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=13147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}