{"id":14286,"date":"2022-01-13T13:22:00","date_gmt":"2022-01-13T13:22:00","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=14286"},"modified":"2022-08-13T11:08:49","modified_gmt":"2022-08-13T11:08:49","slug":"sparklines-javascript","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/","title":{"rendered":"How to Create Sparklines with JavaScript"},"content":{"rendered":"<p><a href=\"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/\"><img decoding=\"async\" class=\"alignnone size-full wp-image-14304\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript.png\" alt=\"Sparkline Chart of Money Heist IMDb Ratings Built with JavaScript\" width=\"100%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript.png 1400w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript-300x158.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript-768x403.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript-1024x538.png 1024w\" sizes=\"(max-width: 1400px) 100vw, 1400px\" \/><\/a>Sparklines are elegant microcharts introduced by <a href=\"https:\/\/en.wikipedia.org\/wiki\/Edward_Tufte\" target=\"_blank\" rel=\"nofollow\">Edward Tufte<\/a>, a renowned statistician and data visualization pioneer. Drawn without any axis and occupying minimal space, these tiny\u00a0graphs are designed\u00a0to\u00a0represent the big picture displaying trends in line with text and within table cells. If you want to\u00a0learn about an easy way\u00a0of building\u00a0a\u00a0sparkline\u00a0chart, it is\u00a0the right place!<\/p>\n<p>In this article, I will show\u00a0you how to\u00a0quickly create cool sparkline charts using JavaScript. With OTT content ruling the world of entertainment these days, let\u2019s have fun learning and look at the IMDb ratings of one of the most popular shows\u00a0nowadays \u2014 <em><a href=\"https:\/\/www.imdb.com\/title\/tt6468322\/\" target=\"_blank\" rel=\"nofollow\">Money Heist<\/a><\/em> (<em>La\u00a0Casa de\u00a0Papel<\/em> in its original Spanish).<\/p>\n<p>Without more ado, come along on this journey of knowledge heist!<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2>JS Sparkline Charts to Be Built<\/h2>\n<p>In the tutorial, we will be creating\u00a0a total of two JavaScript-based sparkline charts with different series.<\/p>\n<p>The line sparklines will display how the\u00a0IMDb ratings of the episodes change over each of the five\u00a0seasons of <em>Money Heist<\/em>.<\/p>\n<p>The column sparklines will indicate how each episode&#8217;s rating stands compared to that season\u2019s average, in percentages: The former will have a value of 100% if it equals the latter and a greater or smaller value for anything more or less than the average, respectively.<\/p>\n<p>Check out how our JS sparkline charts will look and keep reading to delve into this data visualization development process step by step!<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-14297\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-js-final.png\" alt=\"Final JavaScript Sparklines Showing Money Heist IMDb Ratings\" width=\"40%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-js-final.png 375w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-js-final-300x168.png 300w\" sizes=\"(max-width: 375px) 100vw, 375px\" \/><\/p>\n<p>One may think there is a trick somewhere and you need to know a lot about coding but it is actually relatively easy and the final JavaScript code will be lean 40+ lines of Vanilla JS.<\/p>\n<h2>Creating JavaScript Sparkline Chart<\/h2>\n<p>A lovely JS sparkline chart can be created in just four simple steps. Isn\u2019t that perfecto?<\/p>\n<ol>\n<li>Make an HTML page.<\/li>\n<li>Add the script files to be used.<\/li>\n<li>Connect the data.<\/li>\n<li>Write\u00a0the JavaScript\u00a0charting code.<\/li>\n<\/ol>\n<h3>1. Make an HTML page<\/h3>\n<p>To begin with, we need a\u00a0basic HTML page with a <code>&lt;table&gt;<\/code>\u00a0element that will hold all the data values along with the sparkline charts. To\u00a0reference the table\u00a0later in the code, we&#8217;ll provide it\u00a0with an\u00a0ID parameter. For example, &#8220;tb-seasons.&#8221;<\/p>\n<p>Then, let&#8217;s\u00a0add the\u00a0table head\u00a0to display\u00a0the title\u00a0of the whole table and the headings of each column. Long texts\u00a0will be broken\u00a0into\u00a0two lines\u00a0so\u00a0the\u00a0entire sparkline\u00a0chart-based data visualization\u00a0project\u00a0looks neater.<\/p>\n<p>Finally, of course, we also\u00a0need to define the body of the table. It is where our data values and sparkline charts\u00a0themselves will be rendered.<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Sparkline Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html,\r\n      body {\r\n\u00a0\u00a0      width: 100%;\r\n\u00a0\u00a0      margin:0;\r\n\u00a0\u00a0      padding: 0;\r\n      }\r\n      tr { \r\n    \u00a0\u00a0\u00a0\u00a0overflow: hidden;\r\n    \u00a0\u00a0\u00a0\u00a0height: 14px;\r\n    \u00a0\u00a0\u00a0\u00a0white-space: nowrap;\r\n      }\r\n      td {\r\n    \u00a0\u00a0\u00a0\u00a0text-align: center; \r\n    \u00a0\u00a0\u00a0\u00a0vertical-align: middle;\r\n      }\r\n      .chart {\r\n\u00a0\u00a0      height: 20px;\r\n\u00a0\u00a0      width: 80px;\r\n      }\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;table id=\"tb-seasons\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;thead&gt;\r\n\u00a0\u00a0      &lt;tr&gt;\r\n\u00a0\u00a0\u00a0\u00a0      &lt;th id=\"tg-head\" colspan=\"4\"&gt;Money Heist IMDb Ratings&lt;\/th&gt;\r\n\u00a0\u00a0      &lt;\/tr&gt;  \r\n\u00a0\u00a0      &lt;tr&gt;\r\n\u00a0\u00a0\u00a0\u00a0      &lt;th id=\"tg-head\"&gt;Season&lt;\/th&gt;\r\n\u00a0\u00a0\u00a0\u00a0      &lt;th id=\"tg-head\"&gt;Average rating&lt;\/th&gt;\r\n\u00a0\u00a0\u00a0\u00a0      &lt;th id=\"tg-head\"&gt;Rating&lt;br&gt;by episode&lt;\/th&gt;\r\n\u00a0\u00a0\u00a0\u00a0      &lt;th id=\"tg-head\"&gt;% of average&lt;br&gt;by episode&lt;\/th&gt;\r\n\u00a0\u00a0      &lt;\/tr&gt;    \r\n      &lt;\/thead&gt;\r\n      &lt;tbody&gt;\r\n      &lt;\/tbody&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/table&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<p>As you see,\u00a0in this\u00a0first step,\u00a0we\u00a0have also\u00a0specified the styles for the body, each row, and each cell of the table. In this example, the height of the chart\u00a0is\u00a0as small as\u00a020 pixels, and the width of the chart\u00a0is\u00a0only\u00a080 pixels. This is done to showcase that sparkline charts work without\u00a0taking much\u00a0space and\u00a0to drive home the point that\u00a0they are designed to serve as micrographs\u00a0in tables.<\/p>\n<h3>2. Add the script files to be used<\/h3>\n<p>Next, we\u00a0need to reference\u00a0all the required scripts that will be used to create a sparkline chart visualization.<\/p>\n<p>There are many JavaScript charting libraries out there. However, not\u00a0all of them\u00a0support sparkline charts. Here, we will be using\u00a0one that does,\u00a0<a href=\"https:\/\/www.anychart.com\">AnyChart.<\/a>\u00a0It is lightweight, flexible, and a good choice for beginners because there are many <a href=\"https:\/\/www.anychart.com\/products\/anychart\/gallery\/\">examples<\/a> and detailed <a href=\"https:\/\/docs.anychart.com\" target=\"_blank\" rel=\"nofollow\">documentation<\/a>.<\/p>\n<p>Let&#8217;s add the necessary script files from <a href=\"https:\/\/cdn.anychart.com\" target=\"_blank\" rel=\"nofollow\">AnyChart CDN<\/a>.\u00a0To build sparkline charts using\u00a0this JS\u00a0library for data visualization,\u00a0we\u00a0need three specific scripts: the <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#core\" target=\"_blank\" rel=\"nofollow\">core module<\/a>, the <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#sparkline\" target=\"_blank\" rel=\"nofollow\">sparkline module<\/a>, and the <a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Data_Adapter\/Overview#modules\" target=\"_blank\" rel=\"nofollow\">data adapter<\/a> module. So, we&#8217;ll include them\u00a0all in the <code>&lt;head&gt;<\/code> section of the HTML page created in the first step.<\/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 Sparkline Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n    &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-sparkline.min.js\"&gt;&lt;\/script&gt;\r\n    &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-data-adapter.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\u00a0\/\/ The HTML body and table styles.\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\/\/ The table to hold the data values and the charts.\r\n\u00a0\u00a0\u00a0\u00a0&lt;script&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ All the code for the JS sparkline chart will come here.\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/script&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>3. Connect the data<\/h3>\n<p>I have already\u00a0taken\u00a0the\u00a0<em>Money Heist<\/em>\u00a0ratings\u00a0data from the <a href=\"https:\/\/www.imdb.com\/title\/tt6468322\/episodes\/?ref_=tt_ov_epl\" target=\"_blank\" rel=\"nofollow\">IMDb website<\/a> and created a <a href=\"https:\/\/gist.githubusercontent.com\/shacheeswadia\/21ddfa122938e676bf9e7911e1417d9a\/raw\/d28d7a22b968bb39d755285d28ce949b31276628\/sparklineChartData.json\" target=\"_blank\" rel=\"nofollow\">JSON file<\/a> in the format required for our\u00a0sparklines. We will then connect that dataset using the <code>data.loadJsonFile<\/code> function.<\/p>\n<p>Now the stage\u00a0is all\u00a0set, so let&#8217;s\u00a0get to\u00a0immediately\u00a0making\u00a0the forethought interactive sparkline\u00a0graphics\u00a0by writing\u00a0a little bit of JavaScript\u00a0charting code!<\/p>\n<h3>4. Write the JavaScript charting code<\/h3>\n<p>Sparkline charts are rendered within a table. Therefore, creating a table with sparkline charts involves adding data for each row of the table. It may not be as simple as making one single <a href=\"https:\/\/www.anychart.com\/blog\/2017\/10\/25\/javascript-bar-chart-tutorial\/\">bar chart<\/a> or a <a href=\"https:\/\/www.anychart.com\/blog\/2021\/07\/28\/line-chart-js\/\">line chart<\/a>. But we will go through each line of code, so do not worry as you&#8217;ll see\u00a0creating an interactive\u00a0JS sparkline chart\u00a0is\u00a0really\u00a0far from rocket science.<\/p>\n<p>Let\u2019s start with adding a function that encloses the code to ensure that the page is fully loaded before executing any code. Then we\u00a0will add the data file.<\/p>\n<p>The first thing\u00a0to do\u00a0after\u00a0adding\u00a0the data\u00a0is to create\u00a0a function to iterate through data and call another function to create a row for each season.<\/p>\n<pre><code class=\"javascript\">function (data) {\r\n  \/\/ go through the data and add each season's info and charts to the table\r\n  Object.entries(data).forEach(([key, value]) =&gt; createSeason(key, data)); \r\n}<\/code><\/pre>\n<p>Next, let&#8217;s define the\u00a0new function called\u00a0just now.<\/p>\n<p>First, let&#8217;s get\u00a0a link for the table body where we want to add the rows\u00a0using the\u00a0ID\u00a0assigned\u00a0in the first step. Next, we\u00a0will\u00a0add a new row and set\u00a0its height to 30px. In this row, we&#8217;ll insert cells to hold the season number, the average rating of that season, and\u00a0the sparklines. The\u00a0latter will be\u00a0made\u00a0using another function and based on the\u00a0sparkline chart type,\u00a0line or column.<\/p>\n<pre><code class=\"javascript\">function createSeason(season, data){\r\n\r\n  \/\/ get a table link\r\n  var tbodyRef = document.getElementById('tb-seasons').getElementsByTagName('tbody')[0];\r\n  \r\n  \/\/ insert a row at the end of the table\r\n  var newRow = tbodyRef.insertRow();\r\n  newRow.setAttribute('height', '30px');\r\n  \r\n  \/\/ append a season name text node to a cell\r\n  newRow.insertCell().appendChild(document.createTextNode(season));\r\n  \r\n  \/\/ append a season rating cell\r\n  newRow.insertCell().appendChild(document.createTextNode(data[season]\r\n.avg));\r\n  \r\n  \/\/ create a line sparkline chart showing ratings\r\n  var lineDiv = createSparkline(data[season], 'episodeRatings', 'line');\r\n  \r\n  \/\/ append it\r\n  newRow.insertCell().appendChild(lineDiv); \r\n  \r\n  \/\/ create a column sparkline chart showing percentages\r\n  var columnDiv = createSparkline(data[season], 'percentOfAvg', 'column');\r\n  \r\n  \/\/ append it\r\n  newRow.insertCell().appendChild(columnDiv); \r\n\r\n}<\/code><\/pre>\n<p>The last thing\u00a0to do is\u00a0define the function\u00a0that will build the sparkline charts\u00a0with the desired series type.<\/p>\n<pre><code class=\"javascript\">\/\/ create sparkline of a given type, color, and from a given field\r\nfunction createSparkline(data, field, type){\r\n\r\n  var sparkline = anychart.sparkline(data[field]);\r\n  sparkline.seriesType(type);\r\n  \r\n  \/\/ create a div for the sparklines and assign a css class name\r\n  var chartDiv = document.createElement('div');\r\n  chartDiv.setAttribute('class', 'chart');  \r\n  \r\n  sparkline.container(chartDiv);\r\n  sparkline.draw();\r\n  \r\n  return chartDiv;\r\n\r\n}<\/code><\/pre>\n<p>Tada \u2014 beautiful and functional\u00a0interactive\u00a0JS\u00a0sparkline charts are made! Wasn\u2019t it\u00a0even easier than expected?<\/p>\n<p><a href=\"https:\/\/playground.anychart.com\/H7MFdFPA\/\" target=\"_blank\" rel=\"nofollow\"><img decoding=\"async\" class=\"alignnone size-full wp-image-14299\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-js-basic.png\" alt=\"Basic JavaScript Sparkline Chart Example Showing Money Heist IMDb Ratings\" width=\"40%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-js-basic.png 375w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-js-basic-300x168.png 300w\" sizes=\"(max-width: 375px) 100vw, 375px\" \/><\/a><\/p>\n<p>We can immediately\u00a0notice the trend of growing ratings within each season\u00a0of <em>Money Heist<\/em> and that\u00a0the\u00a0last episode is\u00a0always the highest-rated. That\u2019s one of the greatest advantages of sparkline charts.<\/p>\n<p>The interactive version of this\u00a0basic JavaScript\u00a0sparkline chart-based data visualization with the full code\u00a0can be found on\u00a0<a href=\"https:\/\/playground.anychart.com\/H7MFdFPA\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>. Next, we will customize\u00a0the graphs to\u00a0make them\u00a0look even better.<\/p>\n<h2>Customizing Sparklines<\/h2>\n<p>A huge advantage of using a JavaScript charting library with\u00a0the sparkline\u00a0type of data visualization available out of the box,\u00a0like the AnyChart\u00a0JS library, is the ease of creating a basic version along with a plethora of options to\u00a0customize the\u00a0chart. We&#8217;ll improve the look of\u00a0our sparklines right away.<\/p>\n<h3>Modifying the color palette<\/h3>\n<p>A very easy and effective idea to uplift the chart is to use colors that match the data that we are representing. Since our data is about the\u00a0TV series <em>Money Heist<\/em>, we can simply use the red and black colors predominantly seen in any <em>Money Heist<\/em> poster.<\/p>\n<p>Let&#8217;s use the black color to\u00a0depict the line\u00a0sparklines and the red color for the\u00a0column\u00a0sparklines. It can be done by setting the stroke color for the\u00a0former and\u00a0the fill color for the\u00a0latter.<\/p>\n<p>We\u00a0will simply add the color parameters to\u00a0both sparkline\u00a0building\u00a0functions and pass the color values when calling\u00a0them.<\/p>\n<pre><code class=\"javascript\">\/\/ create a line sparkline chart showing ratings\r\nvar lineDiv = createSparkline(data[season], 'episodeRatings', 'line', '#040102');\r\n\r\n\/\/ create a column sparkline chart showing percentages\r\nvar columnDiv = createSparkline(data[season], 'percentOfAvg', 'column', '#cf0011');\r\n\r\n\u2026\r\n\r\nsparkline.fill(color).stroke(color);<\/code><\/pre>\n<h3>Improving the headings<\/h3>\n<p>To make our visual more attractive, we\u00a0can\u00a0push\u00a0some style changes. Let&#8217;s start with the title. We&#8217;ll give\u00a0a class to\u00a0the\u00a0top\u00a0row and\u00a0configure the style\u00a0settings for that class.<\/p>\n<pre><code class=\"html\">&lt;tr class=\"main-heading\"&gt;\r\n\u00a0\u00a0&lt;th id=\"tg-head\" colspan=\"4\"&gt;Money Heist IMDb Ratings&lt;\/th&gt;\r\n&lt;\/tr&gt;\r\n\r\n\u2026\r\n\r\n.main-heading {\r\n  font-family: sans-serif;\r\n  font-size: 14px;\r\n}<\/code><\/pre>\n<p>Similarly, let&#8217;s add some\u00a0custom styles for the headings of the columns.<\/p>\n<pre><code class=\"html\">&lt;tr class=\"col-headings\"&gt;\r\n\u00a0\u00a0&lt;th id=\"tg-head\"&gt;Season&lt;\/th&gt;\r\n\u00a0\u00a0&lt;th id=\"tg-head\"&gt;Average rating&lt;\/th&gt;\r\n\u00a0\u00a0&lt;th id=\"tg-head\"&gt;Rating&lt;br&gt;by episode&lt;\/th&gt;\r\n\u00a0\u00a0&lt;th id=\"tg-head\"&gt;% of average&lt;br&gt;by episode&lt;\/th&gt;\r\n&lt;\/tr&gt;\r\n\r\n\u2026\r\n\r\n.col-headings {\r\n  font-family: sans-serif;\r\n  font-size: 13px;\r\n  color: #7c868e;\r\n  font-weight: 300;\r\n  text-align: left;\r\n}<\/code><\/pre>\n<p>Here is a sneak peek at how stunning the\u00a0sparklines look with just these easy modifications. You can\u00a0take a look at the interactive version\u00a0with the code <a href=\"https:\/\/playground.anychart.com\/NPEIKjaL\/\" target=\"_blank\" rel=\"nofollow\">here<\/a>.<\/p>\n<p><a href=\"https:\/\/playground.anychart.com\/NPEIKjaL\/\" target=\"_blank\" rel=\"nofollow\"><img decoding=\"async\" class=\"alignnone size-full wp-image-14298\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-js-intermediate.png\" alt=\"Intermediate JavaScript Sparkline Chart Example Visualizing Money Heist IMDb Ratings Data\" width=\"40%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-js-intermediate.png 375w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-js-intermediate-300x168.png 300w\" sizes=\"(max-width: 375px) 100vw, 375px\" \/><\/a><\/p>\n<h3>Changing the tooltip<\/h3>\n<p>A tooltip should always add some value and help in showing more information\u00a0when it&#8217;s needed. In our sparkline charts, the default tooltip shows\u00a0X and\u00a0Y values, which is not very insightful. Let&#8217;s make it\u00a0display the\u00a0episode number and the value for each data point \u2014\u00a0episode rating\u00a0in the line\u00a0sparkling charts\u00a0and percentage in\u00a0the column chart.<\/p>\n<p>Just\u00a0like we did for colors, we&#8217;ll add\u00a0the tooltip parameters\u00a0to the functions and pass\u00a0the\u00a0custom\u00a0tooltip text\u00a0according to\u00a0the\u00a0type of sparkline\u00a0series.<\/p>\n<pre><code class=\"javascript\">sparkline.tooltip().format(function() {\r\n  var x = (this.x) + 1;\r\n  return \"E\" + x + \"-\" + this.value + tooltipPostfix;\r\n});<\/code><\/pre>\n<p>That\u2019s it! Visually appealing\u00a0and\u00a0informative sparklines are\u00a0ready!<\/p>\n<p><a href=\"https:\/\/playground.anychart.com\/zRncTQkj\/\" target=\"_blank\" rel=\"nofollow\"><img decoding=\"async\" class=\"alignnone size-full wp-image-14297\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-js-final.png\" alt=\"Final JavaScript Sparkline Chart Visualizing Money Heist IMDb Ratings Data\" width=\"40%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-js-final.png 375w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-js-final-300x168.png 300w\" sizes=\"(max-width: 375px) 100vw, 375px\" \/><\/a><\/p>\n<p>Check out\u00a0the\u00a0final interactive\u00a0JS sparkline chart on\u00a0<a href=\"https:\/\/playground.anychart.com\/zRncTQkj\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>\u00a0where you can also continue improving it, add some other data, and so on.\u00a0The full code is\u00a0also below just in case.<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n\u00a0\u00a0&lt;title&gt;JavaScript Sparkline Chart&lt;\/title&gt;\r\n\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-sparkline.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-data-adapter.min.js\"&gt;&lt;\/script&gt;\r\n\r\n\u00a0\u00a0&lt;table id=\"tb-seasons\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;thead&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;tr class=\"main-heading\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;th id=\"tg-head\" colspan=\"4\"&gt;Money Heist IMDb Ratings&lt;\/th&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/tr&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;tr class=\"col-headings\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;th id=\"tg-head\"&gt;Season&lt;\/th&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;th id=\"tg-head\"&gt;Average rating&lt;\/th&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;th id=\"tg-head\"&gt;Rating&lt;br&gt;by episode&lt;\/th&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;th id=\"tg-head\"&gt;% of average&lt;br&gt;by episode&lt;\/th&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/tr&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/thead&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;tbody&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/tbody&gt;\r\n\u00a0\u00a0&lt;\/table&gt;\r\n\r\n\u00a0\u00a0&lt;style type=\"text\/css\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0html,\r\n\u00a0\u00a0\u00a0\u00a0body {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0margin: 0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0padding: 0;\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0tr {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0overflow: hidden;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0height: 14px;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0white-space: nowrap;\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0td {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0text-align: center;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0vertical-align: middle;\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0.chart {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0height: 20px;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 80px;\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0.main-heading {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0font-family: sans-serif;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0font-size: 14px;\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0.col-headings {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0font-family: sans-serif;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0font-size: 13px;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0color: #7c868e;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0font-weight: 300;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0text-align: left;\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0&lt;\/style&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n\r\n\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\r\n\u00a0\u00a0&lt;script&gt;\r\n\u00a0\u00a0\u00a0\u00a0anychart.onDocumentReady(function () {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0anychart.data.loadJsonFile('https:\/\/gist.githubusercontent.com\/shacheeswadia\/21ddfa122938e676bf9e7911e1417d9a\/raw\/d28d7a22b968bb39d755285d28ce949b31276628\/sparklineChartData.json',\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0function (data) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ go through the data and add each season's info and charts to the table\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Object.entries(data).forEach(([key, value]) =&gt; createSeason(key, data));\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0);\r\n\u00a0\u00a0\u00a0\u00a0});\r\n\r\n\u00a0\u00a0\u00a0\u00a0function createSeason(season, data) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ get a table link\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var tbodyRef = document.getElementById('tb-seasons').getElementsByTagName('tbody')[0];\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ insert a row at the end of the table\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var newRow = tbodyRef.insertRow();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0newRow.setAttribute('height', '30px');\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ append a season name text node to a cell\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0newRow.insertCell().appendChild(document.createTextNode(season));\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ append a season rating cell\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0newRow.insertCell().appendChild(document.createTextNode(data[season].avg));\r\n      \/\/ create a line sparkline chart showing ratings\r\n \u00a0\u00a0\u00a0\u00a0\u00a0var lineDiv = createSparkline(data[season], 'episodeRatings', 'line', '#040102', 'Rating', '');\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ append it\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0newRow.insertCell().appendChild(lineDiv);\r\n      \/\/ create a column sparkline chart showing percentages\r\n \u00a0\u00a0\u00a0\u00a0\u00a0var columnDiv = createSparkline(data[season], 'percentOfAvg', 'column', '#cf0011', 'Percent of average', '%');\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ append it\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0newRow.insertCell().appendChild(columnDiv);\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0\/\/ create sparkline of a given type, color, and from a given field\r\n\u00a0\u00a0\u00a0\u00a0function createSparkline(data, field, type, color, tooltipText, tooltipPostfix) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var sparkline = anychart.sparkline(data[field]);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sparkline.seriesType(type);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sparkline.fill(color).stroke(color);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sparkline.tooltip().format(function () {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var x = (this.x) + 1;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return \"E\" + x + \"-\" + this.value + tooltipPostfix;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ create a div for the sparklines and assign a css class name\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var chartDiv = document.createElement('div');\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chartDiv.setAttribute('class', 'chart');\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sparkline.container(chartDiv);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sparkline.draw();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return chartDiv;\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0&lt;\/script&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>You see it is really interesting and easy to build\u00a0elegant sparklines\u00a0with\u00a0JavaScript. To\u00a0see what else is possible, don&#8217;t hesitate to\u00a0look at\u00a0the <a href=\"https:\/\/docs.anychart.com\/Basic_Charts\/Sparkline_Chart\" target=\"_blank\" rel=\"nofollow\">sparkline charting docs<\/a>\u00a0and <a href=\"https:\/\/www.anychart.com\/products\/anychart\/gallery\/Sparkline_Charts\/\">examples<\/a> in the AnyChart gallery.<\/p>\n<p>So then, let us all use our brains not for plotting\u00a0a bank\u00a0robbery but for creating some lovely visual charts of this and many <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Supported_Charts_Types\" target=\"_blank\" rel=\"nofollow\">other types<\/a>!<\/p>\n<hr \/>\n<p><em>We want to thank freelance data visualizer Shachee Swadia for creating this amazing JavaScript Sparkline Chart tutorial as a guest post.<\/em><\/p>\n<p><em>To learn more about sparkline charts, visit <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/sparkline-chart\">Chartopedia<\/a>.<\/em><\/p>\n<p><em>We also have many other <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JS chart tutorials<\/a> in case you are interested.<\/em><\/p>\n<p><em>Got an idea of a no less awesome guest post?\u00a0We are eager to <a href=\"https:\/\/www.anychart.com\/support\/\">hear from you<\/a>!<\/em><\/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>Sparklines are elegant microcharts introduced by Edward Tufte, a renowned statistician and data visualization pioneer. Drawn without any axis and occupying minimal space, these tiny\u00a0graphs are designed\u00a0to\u00a0represent the big picture displaying trends in line with text and within table cells. If you want to\u00a0learn about an easy way\u00a0of building\u00a0a\u00a0sparkline\u00a0chart, it is\u00a0the right place! In this [&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,23,13,279,4],"tags":[843,53,254,1758,3149,284,127,166,258,2385,3155,282,471,266,620,916,1759,294,2220,54,1389,1760,2757,256,1111,350,844,130,165,313,1370,133,775,145,179,1498,3080,805,1762,2013,2014,32,55,503,716,1764,504,144,2016,167,151,36,907,141,249,3111,81,57,1238,142,96,99,58,65,56,1937,2335,1938,3158,3157,3154,3160,3159,3156,1228,669,131,202,201,459,30,41,172,832,954,293,899,1939,2015,2816,1763,804],"class_list":["post-14286","post","type-post","status-publish","format-standard","hentry","category-anychart-charting-component","category-big-data","category-html5","category-javascript","category-javascript-chart-tutorials","category-tips-and-tricks","tag-advanced-data-visualization","tag-anychart","tag-chart","tag-chart-design","tag-chart-development","tag-chart-examples","tag-chart-types","tag-charting","tag-charts","tag-coding","tag-column-sparkline-chart","tag-data","tag-data-analysis","tag-data-analytics","tag-data-analytics-examples","tag-data-api","tag-data-design","tag-data-science","tag-data-visual","tag-data-visualization","tag-data-visualization-best-pracices","tag-data-visualization-design","tag-data-visualization-development","tag-data-visualization-examples","tag-data-visualization-practice","tag-data-visualization-projects","tag-data-visualization-tutorial","tag-data-visualization-weekly","tag-data-visualizations","tag-data-visuals","tag-data-viz-examples","tag-dataviz","tag-dataviz-projects","tag-dataviz-weekly","tag-design","tag-example","tag-films","tag-front-end-development","tag-guest-post","tag-html","tag-html-charts","tag-html5","tag-html5-charts","tag-imdb","tag-imdb-data","tag-imdb-data-visualization","tag-imdb-user-ratings","tag-infographics","tag-information-visualization","tag-interactive-charts","tag-interactive-visualizations","tag-javascript","tag-javascript-chart-tutorial","tag-javascript-charting","tag-javascript-charting-api","tag-javascript-charting-features","tag-javascript-charting-library","tag-javascript-charts","tag-javascript-graph","tag-javascript-graphics","tag-javascript-graphics-library","tag-javascript-library","tag-js-chart","tag-js-charting","tag-js-charts","tag-json","tag-json-charts","tag-json-data-visualization","tag-kaggle","tag-la-casa-de-papel","tag-line-sparkline-chart","tag-micro-chart","tag-microchart","tag-money-heist","tag-movie-data","tag-movies","tag-recap-of-the-week","tag-sparkline-chart","tag-sparklines","tag-statistics","tag-tips-and-tricks","tag-tufte","tag-tutorial","tag-visual-data","tag-visual-data-analytics","tag-visualization","tag-visualizations","tag-visualizing-json-data","tag-web-charts","tag-web-design","tag-web-developers","tag-web-development","wpautop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Create Sparklines with JavaScript<\/title>\n<meta name=\"description\" content=\"Learn how to quickly build JavaScript sparkline charts in a stepwise tutorial. Visualizing the IMDb ratings of Money Heist in line and column sparklines.\" \/>\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\/01\/13\/sparklines-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Sparkline Charts with JS\" \/>\n<meta property=\"og:description\" content=\"Learn how to quickly build JavaScript sparkline charts in a stepwise tutorial. Visualizing Money Heist&#039;s IMDb ratings in line and column sparklines.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-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-01-13T13:22:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-13T11:08:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript-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 Sparkline Charts with JS\" \/>\n<meta name=\"twitter:description\" content=\"Learn how to quickly build JavaScript sparkline charts in a stepwise tutorial. Visualizing Money Heist&#039;s IMDb ratings in line and column sparklines.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript-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=\"13 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\/01\/13\/sparklines-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/\"},\"author\":{\"name\":\"Shachee Swadia\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"headline\":\"How to Create Sparklines with JavaScript\",\"datePublished\":\"2022-01-13T13:22:00+00:00\",\"dateModified\":\"2022-08-13T11:08:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/\"},\"wordCount\":1527,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript.png\",\"keywords\":[\"advanced data visualization\",\"AnyChart\",\"chart\",\"chart design\",\"chart development\",\"chart examples\",\"chart types\",\"charting\",\"charts\",\"coding\",\"column sparkline chart\",\"data\",\"data analysis\",\"data analytics\",\"data analytics examples\",\"data API\",\"data design\",\"data science\",\"data visual\",\"Data Visualization\",\"data visualization best practices\",\"data visualization design\",\"data visualization development\",\"data visualization examples\",\"data visualization practice\",\"data visualization projects\",\"data visualization tutorial\",\"data visualization weekly\",\"data visualizations\",\"data visuals\",\"data viz examples\",\"dataviz\",\"dataviz projects\",\"dataviz weekly\",\"design\",\"example\",\"films\",\"front-end development\",\"guest post\",\"HTML\",\"HTML charts\",\"HTML5\",\"html5 charts\",\"IMDb\",\"IMDb data\",\"IMDb data visualization\",\"IMDb user ratings\",\"infographics\",\"information visualization\",\"interactive charts\",\"interactive visualizations\",\"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\",\"JSON\",\"JSON charts\",\"JSON data visualization\",\"Kaggle\",\"La casa de papel\",\"line sparkline chart\",\"micro chart\",\"microchart\",\"Money Heist\",\"movie data\",\"movies\",\"recap of the week\",\"sparkline chart\",\"sparklines\",\"statistics\",\"Tips and tricks\",\"Tufte\",\"tutorial\",\"visual data\",\"visual data analytics\",\"visualization\",\"visualizations\",\"visualizing JSON data\",\"web charts\",\"web design\",\"web developers\",\"web development\"],\"articleSection\":[\"AnyChart Charting Component\",\"Big Data\",\"HTML5\",\"JavaScript\",\"JavaScript Chart Tutorials\",\"Tips and Tricks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/\",\"name\":\"How to Create Sparklines with JavaScript\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript.png\",\"datePublished\":\"2022-01-13T13:22:00+00:00\",\"dateModified\":\"2022-08-13T11:08:49+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"description\":\"Learn how to quickly build JavaScript sparkline charts in a stepwise tutorial. Visualizing the IMDb ratings of Money Heist in line and column sparklines.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript.png\",\"width\":1400,\"height\":735},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create Sparklines 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":"How to Create Sparklines with JavaScript","description":"Learn how to quickly build JavaScript sparkline charts in a stepwise tutorial. Visualizing the IMDb ratings of Money Heist in line and column sparklines.","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\/01\/13\/sparklines-javascript\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Sparkline Charts with JS","og_description":"Learn how to quickly build JavaScript sparkline charts in a stepwise tutorial. Visualizing Money Heist's IMDb ratings in line and column sparklines.","og_url":"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2022-01-13T13:22:00+00:00","article_modified_time":"2022-08-13T11:08:49+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript-social.png","type":"","width":"","height":""}],"author":"Shachee Swadia","twitter_card":"summary_large_image","twitter_title":"How to Create Sparkline Charts with JS","twitter_description":"Learn how to quickly build JavaScript sparkline charts in a stepwise tutorial. Visualizing Money Heist's IMDb ratings in line and column sparklines.","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript-social.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Shachee Swadia","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/"},"author":{"name":"Shachee Swadia","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"headline":"How to Create Sparklines with JavaScript","datePublished":"2022-01-13T13:22:00+00:00","dateModified":"2022-08-13T11:08:49+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/"},"wordCount":1527,"commentCount":0,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript.png","keywords":["advanced data visualization","AnyChart","chart","chart design","chart development","chart examples","chart types","charting","charts","coding","column sparkline chart","data","data analysis","data analytics","data analytics examples","data API","data design","data science","data visual","Data Visualization","data visualization best practices","data visualization design","data visualization development","data visualization examples","data visualization practice","data visualization projects","data visualization tutorial","data visualization weekly","data visualizations","data visuals","data viz examples","dataviz","dataviz projects","dataviz weekly","design","example","films","front-end development","guest post","HTML","HTML charts","HTML5","html5 charts","IMDb","IMDb data","IMDb data visualization","IMDb user ratings","infographics","information visualization","interactive charts","interactive visualizations","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","JSON","JSON charts","JSON data visualization","Kaggle","La casa de papel","line sparkline chart","micro chart","microchart","Money Heist","movie data","movies","recap of the week","sparkline chart","sparklines","statistics","Tips and tricks","Tufte","tutorial","visual data","visual data analytics","visualization","visualizations","visualizing JSON data","web charts","web design","web developers","web development"],"articleSection":["AnyChart Charting Component","Big Data","HTML5","JavaScript","JavaScript Chart Tutorials","Tips and Tricks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/","url":"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/","name":"How to Create Sparklines with JavaScript","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript.png","datePublished":"2022-01-13T13:22:00+00:00","dateModified":"2022-08-13T11:08:49+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"description":"Learn how to quickly build JavaScript sparkline charts in a stepwise tutorial. Visualizing the IMDb ratings of Money Heist in line and column sparklines.","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/sparkline-chart-of-money-heist-ratings-in-javascript.png","width":1400,"height":735},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2022\/01\/13\/sparklines-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create Sparklines 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\/14286","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=14286"}],"version-history":[{"count":33,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14286\/revisions"}],"predecessor-version":[{"id":15515,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14286\/revisions\/15515"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=14286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=14286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=14286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}