{"id":14503,"date":"2022-02-03T21:43:43","date_gmt":"2022-02-03T21:43:43","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=14503"},"modified":"2022-08-13T11:08:39","modified_gmt":"2022-08-13T11:08:39","slug":"error-chart-js","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/","title":{"rendered":"Creating Error Chart in JavaScript"},"content":{"rendered":"<p><a href=\"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/\"><img decoding=\"async\" class=\"alignnone size-full wp-image-14509\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-js.png\" alt=\"JavaScript Error Chart of Perceived Threat of COVID-19 by Political Affiliation\" width=\"100%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-js.png 1450w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-js-300x169.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-js-768x432.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-js-1024x576.png 1024w\" sizes=\"(max-width: 1450px) 100vw, 1450px\" \/><\/a>Need a cool interactive <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/error-chart\/\">error chart<\/a>\u00a0visualization for\u00a0your web page or app? Let me be your guide!\u00a0Follow this tutorial and you&#8217;ll learn how to\u00a0easily create elegant interactive error charts using JavaScript.<\/p>\n<p>Here, I will be visualizing data on COVID-19 threat\u00a0perceptions in the United States during the first six months of the pandemic, by political affiliation. So you will also be able to\u00a0explore the divergence in those attitudes between Democrats and Republicans. The data originates from the article <a href=\"https:\/\/journals.plos.org\/plosone\/article?id=10.1371\/journal.pone.0250123\" target=\"_blank\" rel=\"nofollow\">&#8220;COVID-19 and vaccine hesitancy: A longitudinal study&#8221;<\/a>\u00a0published in the <em>Plos One<\/em> journal.<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2>What Is Error Chart<\/h2>\n<p>Before I begin, I&#8217;d like to make sure\u00a0we are on the same page in understanding what an error chart\u00a0actually is and how it works.<\/p>\n<p>An error chart is a type of data visualization commonly used to show\u00a0uncertainty or variability of data with the help of so-called error bars. The latter\u00a0can be added on top of\u00a0the main graph\u00a0to represent value ranges in addition to\u00a0average (mean) values plotted\u00a0in the form of lines, columns, bars, areas, markers, or other types of series.<\/p>\n<h2>Error Chart Preview<\/h2>\n<p>Now, let me show you how the final error chart will look to get you all even more excited about learning how to create one yourself!<\/p>\n<p>So, I am going to represent the perceived threat of COVID-19\u00a0among the American population by political affiliation over\u00a0time, from March to August 2020. Precisely, I will show the <a href=\"https:\/\/journals.plos.org\/plosone\/article?id=10.1371\/journal.pone.0250123\" target=\"_blank\" rel=\"nofollow\">results<\/a> of the longitudinal survey conducted by Ariel Fridman, Rachel Gershon, and Ayelet Gneezy in the following way. Mean responses of\u00a0self-identified Democrats and Republicans will be visualized in\u00a0two <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/line-chart\/\">line charts<\/a>, and the error bars will represent the 95% confidence intervals. In the survey, the scale for the responses was from 1 to 7, where 1\u00a0is\u00a0the minimum perceived threat and 7 is the\u00a0maximum.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-14511\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart.png\" alt=\"JS Error Chart That Will Be Built Along the Tutorial\" width=\"100%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart.png 1150w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-300x167.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-768x427.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-1024x570.png 1024w\" sizes=\"(max-width: 1150px) 100vw, 1150px\" \/><\/p>\n<h2>Basic JS Error Chart in 4 Simple Steps<\/h2>\n<p>An error chart is pretty simple to create with a\u00a0good JavaScript charting library. Here, I am going to use <a href=\"https:\/\/www.anychart.com\">AnyChart<\/a>,\u00a0which is a flexible and easy-to-use one. It has great <a href=\"https:\/\/docs.anychart.com\" target=\"_blank\" rel=\"nofollow\">documentation<\/a>, a lot of useful <a href=\"https:\/\/www.anychart.com\/products\/anychart\/gallery\/\">examples<\/a>, and a <a href=\"https:\/\/playground.anychart.com\" target=\"_blank\" rel=\"nofollow\">playground<\/a> to\u00a0experiment with the data visualization code on your own.<\/p>\n<p>Basic knowledge of web technologies is always good to have. But when it comes to creating interactive\u00a0JavaScript-based graphs like this, everything\u00a0is quite straightforward even without much of such background.<\/p>\n<p>The process of building a JS error chart can be split into the following four basic steps:<\/p>\n<ol>\n<li>Create an HTML page.<\/li>\n<li>Include JavaScript files.<\/li>\n<li>Add data.<\/li>\n<li>Write\u00a0some JS charting code.<\/li>\n<\/ol>\n<h3>1. Create an HTML page<\/h3>\n<p>The first thing I am going to do is create a\u00a0basic HTML page to hold my error chart. There, I define a block element with an id attribute (let it be \u201ccontainer\u201d). Next, I\u00a0add the style attributes in the <code>&lt;head&gt;<\/code> section, where I set the width and height of the <code>&lt;div&gt;<\/code>\u00a0as 100% so that my chart renders over the whole page.<\/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 Error Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; height: 100%; margin: 0; padding: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \r\n\u00a0\u00a0\u00a0\u00a0&lt;\/style&gt;\r\n\u00a0\u00a0&lt;\/head&gt;\r\n\u00a0\u00a0&lt;body&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>2. Include JavaScript files<\/h3>\n<p>Then, I need to include all necessary scripts. I\u00a0am going to use them from the <a href=\"https:\/\/cdn.anychart.com\" target=\"_blank\" rel=\"nofollow\">CDN,<\/a>\u00a0but you can\u00a0also download the files if you want.<\/p>\n<p>For\u00a0an error chart, all I need is the <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#base\" target=\"_blank\" rel=\"nofollow\">base<\/a>\u00a0module. I reference it\u00a0in the <code>&lt;head&gt;<\/code> section of the\u00a0web page.<\/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 Error Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-base.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\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&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 JS error chart code will be 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. Set the data<\/h3>\n<p>There are\u00a0<a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Supported_Data_Formats\" target=\"_blank\" rel=\"nofollow\">multiple ways to load data<\/a>. In this case, the\u00a0amount of data I want to visualize is pretty small. So I\u00a0can just go ahead and put it\u00a0right there in the code.<\/p>\n<p>I am going to plot two series, for Democrats and Republicans. So I add the data like this:<\/p>\n<pre><code class=\"javascript\">var data1 = anychart.data\r\n  .set([\r\n    ['Mar', 4.26, 0.1, 0.1],\r\n    ['Apr', 4.46, 0.11, 0.11],\r\n    ['May', 4.36, 0.126, 0.126],\r\n    ['June', 4.29, 0.132, 0.132],\r\n    ['July', 4.49, 0.124, 0.124],\r\n    ['Aug', 4.47, 0.124, 0.124]\r\n  ])\r\n  \r\nvar data2 = anychart.data\r\n  .set([\r\n    ['Mar', 3.9, 0.144, 0.144],\r\n    ['Apr', 4.09, 0.172, 0.172],\r\n    ['May', 3.71, 0.196, 0.196],\r\n    ['June', 3.54, 0.198, 0.198],\r\n    ['July', 3.78, 0.196, 0.196],\r\n    ['Aug', 3.7, 0.194, 0.195]\r\n  ])<\/code><\/pre>\n<p>Now that all the background work\u00a0has been sorted out, let\u2019s get to the main part of creating a JavaScript error chart. Well, it takes only a few\u00a0more lines of code.<\/p>\n<h3>4. Write\u00a0some JS\u00a0charting\u00a0code<\/h3>\n<p>To begin with, I add a function that encloses all the JavaScript charting code to ensure that the page is ready before executing anything. Inside this function, I create\u00a0a line chart and\u00a0provide it with a title.<\/p>\n<pre><code class=\"javascript\">\/\/ create a line chart\r\nvar chart = anychart.line();\r\n\r\n\/\/ add a chart title \r\nchart.title('Perceived threat of COVID-19 by political affiliation (March\u2013August 2020)');\r\n<\/code><\/pre>\n<p>Next, I set the data for both series in the form of an array as described in the previous step. And I use the <code>mapAs<\/code> function to map what each element of my array corresponds to.<\/p>\n<pre><code class=\"javascript\">\/\/ create a dataset (democrats)\r\nvar data1 = anychart.data\r\n  .set([\r\n    ['Mar', 4.26, 0.1, 0.1],\r\n    ['Apr', 4.46, 0.11, 0.11],\r\n    ['May', 4.36, 0.126, 0.126],\r\n    ['June', 4.29, 0.132, 0.132],\r\n    ['July', 4.49, 0.124, 0.124],\r\n    ['Aug', 4.47, 0.124, 0.124]\r\n  ])\r\n  \/\/ map the data\r\n  .mapAs({\r\n    x: 0,\r\n    value: 1,\r\n    valueLowerError: 2,\r\n    valueUpperError: 3\r\n  });\r\n\r\n\/\/ create a dataset (republicans)\r\nvar data2 = anychart.data\r\n  .set([\r\n    ['Mar', 3.9, 0.144, 0.144],\r\n    ['Apr', 4.09, 0.172, 0.172],\r\n    ['May', 3.71, 0.196, 0.196],\r\n    ['June', 3.54, 0.198, 0.198],\r\n    ['July', 3.78, 0.196, 0.196],\r\n    ['Aug', 3.7, 0.194, 0.195]\r\n  ])\r\n  \/\/ map the data\r\n  .mapAs({\r\n    x: 0,\r\n    value: 1,\r\n    valueLowerError: 2,\r\n    valueUpperError: 3\r\n  });<\/code><\/pre>\n<p>Since all the data values lie within a range, I\u00a0configure the Y-axis accordingly using the <code>yScale<\/code> function.<\/p>\n<pre><code class=\"javascript\">var yScale = chart.yScale();\r\nyScale.minimum(3.2);\r\nyScale.maximum(4.8);<\/code><\/pre>\n<p>Finally, I create a line series for\u00a0each dataset, set the container reference, and draw the resulting error graphics.<\/p>\n<pre><code class=\"javascript\">\/\/ create a line series for the first dataset\r\nvar series1 = chart.line(data1);\r\n\r\n\/\/ create a line series for the second dataset\r\nvar series2 = chart.line(data2);\r\n\r\n\/\/ set a container id for the chart\r\nchart.container('container');\r\n\r\n\/\/ command to draw the chart\r\nchart.draw();<\/code><\/pre>\n<p>Aha \u2014 a lovely interactive error chart is right there on the page!<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-\" src=\"https:\/\/playground.anychart.com\/irYKkg0W\/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-{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>We can clearly see a divergence in COVID-19 threat perceptions between\u00a0Democrats (the top line) and Republicans (the bottom line) during the first months of the pandemic, and the corresponding over-time trends\u00a0appear to be\u00a0quite significantly different.<\/p>\n<p>You are more than welcome to take a closer look at this initial JavaScript-based error chart and play around with its code on <a href=\"https:\/\/playground.anychart.com\/irYKkg0W\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a> or <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/KKvjQaL\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a>.<\/p>\n<h2>Error Chart Customization<\/h2>\n<p>Although a basic error chart is here and ready to do its job, there is\u00a0always room for improvement in\u00a0the look, feel, and legibility. The AnyChart JS library has a lot of great options to\u00a0enhance\u00a0an error chart and make it even more elegant and informative. So, let me walk you through a few quick customization steps that you might like to take.<\/p>\n<h3>1. Add a grid and axis ticks<\/h3>\n<p>First, I want to add some more ticks\u00a0along\u00a0the Y-axis and\u00a0display\u00a0grid lines to\u00a0facilitate understanding the values when someone is exploring this error chart.<\/p>\n<pre><code class=\"javascript\">var ticks = chart.yScale().ticks();\r\nticks.interval(0.2);\r\n\r\nchart.yGrid().enabled(true).stroke({\r\n  \/\/ customize the stroke color\r\n  color: \"#ededed\",\r\n});<\/code><\/pre>\n<h3>2. Change the colors<\/h3>\n<p>The colors blue and red are commonly used to represent Democrats and Republicans, respectively. So, let me change the colors of the series lines and error bars accordingly using the <code>stroke<\/code> attribute to make the graphic\u00a0more intuitive.<\/p>\n<pre><code class=\"javascript\">\/\/ create a line series for the first dataset\r\nvar series1 = chart.line(data1).stroke(\"#031bbb\", 3);\r\n\r\n\/\/ create error bars for the first series\r\nvar error1 = series1.error();\r\nerror1.valueErrorStroke(\"#031bbb\", 1);\r\n\r\n\/\/ create a line series for the second dataset\r\nvar series2 = chart.line(data2).stroke(\"#de0100\", 3);\r\n\r\n\/\/ create error bars for the second series\r\nvar error2 = series2.error();\r\nerror2.valueErrorStroke(\"#de0100\", 1);<\/code><\/pre>\n<p>As you see, I have also increased the stroke width to make the lines more prominent.<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-UKkV1F7X\" src=\"https:\/\/playground.anychart.com\/UKkV1F7X\/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-UKkV1F7X{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>Check out this JS error chart\u00a0with the code\u00a0on <a href=\"https:\/\/playground.anychart.com\/UKkV1F7X\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a> or <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/XWaLoVG\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a>.<\/p>\n<h3>3. Add markers<\/h3>\n<p>To emphasize individual values on the line graphs, I want to add two different types of markers to both series, specifying their type, size, and color.<\/p>\n<pre><code class=\"javascript\">\/\/ set markers for the first series\r\nvar series1 = chart.marker(data1).type(\"circle\").size(5).stroke(\"#031bbb\", 1).fill(\"#0066cc\");\r\n   \r\n\/\/ set markers for the second series\r\nvar series2 = chart.marker(data2).type(\"square\").size(5).stroke(\"#de0100\", 1).fill(\"#de0100\");<\/code><\/pre>\n<h3>4. Enhance the tooltip<\/h3>\n<p>The default tooltip is not\u00a0much informative. But I can easily make it show the series name, mean value, and upper\/lower error values.<\/p>\n<p>To start with,\u00a0I name the series:<\/p>\n<pre><code class=\"javascript\">series1\r\n  .name('Democrats');\r\n\r\nseries2\r\n  .name('Republicans');<\/code><\/pre>\n<p>I also want to split the tooltip, providing each series with its own one:<\/p>\n<pre><code class=\"javascript\">var tooltip = chart.tooltip();\r\ntooltip.displayMode(\"separated\");<\/code><\/pre>\n<p>Finally, I format the way the values\u00a0are displayed and set the tooltip position.<\/p>\n<pre><code class=\"javascript\">\/\/ configure the tooltip formatter\r\ntooltip\r\n  .fontColor('#E1E1E1')\r\n  .titleFormat('{%seriesName}')\r\n  .format(function () {\r\n    return (\r\n      'Mean value: ' +\r\n      this.value +\r\n      '\\nUpper error value: ' +\r\n      this.valueLowerError +\r\n      '\\nLower error value: ' +\r\n      this.valueUpperError\r\n    );\r\n  });\r\n\r\n\/\/ set the tooltip position\r\nchart.tooltip().positionMode('point');<\/code><\/pre>\n<p>A stunning, insightful JavaScript (HTML5) error chart is all ready! These easy, yet effective changes make the visualization so much more engaging!<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-m3sXHVgO\" src=\"https:\/\/playground.anychart.com\/m3sXHVgO\/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-m3sXHVgO{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>Look at the entire final code and play around with\u00a0this interactive JS error chart on <a href=\"https:\/\/playground.anychart.com\/m3sXHVgO\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a> or <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/LYjKqOy\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a>.<\/p>\n<h2>Conclusion<\/h2>\n<p>The threat of COVID-19 may not be over yet.\u00a0But I hope that with the help of this tutorial, it will never be stressful for you\u00a0to create\u00a0interactive\u00a0error charts for the web using JavaScript!<\/p>\n<p>If you have any questions, please do not hesitate to ask them in the comments section below. Thanks.<\/p>\n<hr \/>\n<p><em>The team of AnyChart thanks Shachee Swadia for writing this great JavaScript Error Chart tutorial as a guest post for the blog.<\/em><\/p>\n<p><em>Error charts are described in <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/error-chart\">Chartopedia<\/a>, our comprehensive guide for choosing the right chart type.<\/em><\/p>\n<p><em>There are also other awesome <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JavaScript charting tutorials<\/a> available in our blog.<\/em><\/p>\n<p><em>Want to contribute a guest post? We will be glad 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>Need a cool interactive error chart\u00a0visualization for\u00a0your web page or app? Let me be your guide!\u00a0Follow this tutorial and you&#8217;ll learn how to\u00a0easily create elegant interactive error charts using JavaScript. Here, I will be visualizing data on COVID-19 threat\u00a0perceptions in the United States during the first six months of the pandemic, by political affiliation. So [&hellip;]<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,263,23,13,279,4],"tags":[843,784,53,3173,2000,847,1758,3149,284,258,1766,1771,1772,1800,1769,3244,3243,3245,1948,471,266,620,1292,880,806,1759,509,2220,2838,54,1389,1760,2757,256,1111,844,165,313,1370,133,774,775,720,718,179,214,213,805,1762,2013,2014,32,55,144,167,146,151,36,907,141,249,3111,81,57,1238,142,96,134,58,65,56,101,721,719,2986,834,459,1226,30,172,309,2250,1947,2674,1763,804],"class_list":["post-14503","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-americans","tag-anychart","tag-app-development","tag-best-data-visualization-tool","tag-best-data-visualization-tools","tag-chart-design","tag-chart-development","tag-chart-examples","tag-charts","tag-coronavirus","tag-coronavirus-data","tag-coronavirus-data-visualization","tag-coronavirus-pandemic","tag-covid-19","tag-covid-19-perception","tag-covid-19-threat","tag-covid-19-threat-perception","tag-covid-19-vaccine","tag-data-analysis","tag-data-analytics","tag-data-analytics-examples","tag-data-chart","tag-data-charting","tag-data-charts","tag-data-design","tag-data-graphics","tag-data-visual","tag-data-visualisation","tag-data-visualization","tag-data-visualization-best-pracices","tag-data-visualization-design","tag-data-visualization-development","tag-data-visualization-examples","tag-data-visualization-practice","tag-data-visualization-tutorial","tag-data-visualizations","tag-data-visuals","tag-data-viz-examples","tag-dataviz","tag-dataviz-examples","tag-dataviz-projects","tag-democratic-party","tag-democrats","tag-design","tag-error-bars","tag-error-chart","tag-front-end-development","tag-guest-post","tag-html","tag-html-charts","tag-html5","tag-html5-charts","tag-infographics","tag-interactive-charts","tag-interactive-data-visualization","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-technologies","tag-js-chart","tag-js-charting","tag-js-charts","tag-js-graphics","tag-republican-party","tag-republicans","tag-statistic-visualization","tag-statistical-analysis","tag-statistics","tag-statistics-visualization","tag-tips-and-tricks","tag-tutorial","tag-united-states","tag-vaccination","tag-vaccine","tag-vaccine-skepticism","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>Error Chart and How To Create One in JavaScript HTML5<\/title>\n<meta name=\"description\" content=\"Check out a stepwise guide for how to create a cool Error Chart using JavaScript. Visualizing COVID-19 threat perceptions of Democrats and Republicans.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Creating Error Chart in JavaScript\" \/>\n<meta property=\"og:description\" content=\"Learn how to create a cool Error Chart using JavaScript. Visualizing COVID-19 threat perceptions of Democrats and Republicans.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/\" \/>\n<meta property=\"og:site_name\" content=\"AnyChart News\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/AnyCharts\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-03T21:43:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-13T11:08:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-javascript.png\" \/>\n<meta name=\"author\" content=\"Shachee Swadia\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Creating Error Chart in JavaScript\" \/>\n<meta name=\"twitter:description\" content=\"Learn how to create a cool Error Chart using JavaScript. Visualizing COVID-19 threat perceptions of Democrats and Republicans.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-javascript.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=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/\"},\"author\":{\"name\":\"Shachee Swadia\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"headline\":\"Creating Error Chart in JavaScript\",\"datePublished\":\"2022-02-03T21:43:43+00:00\",\"dateModified\":\"2022-08-13T11:08:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/\"},\"wordCount\":1249,\"commentCount\":1,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-js.png\",\"keywords\":[\"advanced data visualization\",\"Americans\",\"AnyChart\",\"app development\",\"best data visualization tool\",\"best data visualization tools\",\"chart design\",\"chart development\",\"chart examples\",\"charts\",\"coronavirus\",\"coronavirus data\",\"coronavirus data visualization\",\"coronavirus pandemic\",\"COVID-19\",\"COVID-19 perception\",\"COVID-19 threat\",\"COVID-19 threat perception\",\"COVID-19 vaccine\",\"data analysis\",\"data analytics\",\"data analytics examples\",\"data chart\",\"data charting\",\"data charts\",\"data design\",\"data graphics\",\"data visual\",\"data visualisation\",\"Data Visualization\",\"data visualization best practices\",\"data visualization design\",\"data visualization development\",\"data visualization examples\",\"data visualization practice\",\"data visualization tutorial\",\"data visualizations\",\"data visuals\",\"data viz examples\",\"dataviz\",\"dataviz examples\",\"dataviz projects\",\"Democratic Party\",\"Democrats\",\"design\",\"error bars\",\"error chart\",\"front-end development\",\"guest post\",\"HTML\",\"HTML charts\",\"HTML5\",\"html5 charts\",\"infographics\",\"interactive charts\",\"interactive data visualization\",\"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 technologies\",\"js chart\",\"js charting\",\"js charts\",\"JS graphics\",\"Republican Party\",\"Republicans\",\"statistic visualization\",\"statistical analysis\",\"statistics\",\"statistics visualization\",\"Tips and tricks\",\"tutorial\",\"united states\",\"vaccination\",\"vaccine\",\"vaccine skepticism\",\"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\/02\/03\/error-chart-js\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/\",\"name\":\"Error Chart and How To Create One in JavaScript HTML5\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-js.png\",\"datePublished\":\"2022-02-03T21:43:43+00:00\",\"dateModified\":\"2022-08-13T11:08:39+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"description\":\"Check out a stepwise guide for how to create a cool Error Chart using JavaScript. Visualizing COVID-19 threat perceptions of Democrats and Republicans.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-js.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-js.png\",\"width\":1450,\"height\":815},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Creating Error Chart in JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\",\"url\":\"https:\/\/www.anychart.com\/blog\/\",\"name\":\"AnyChart News\",\"description\":\"AnyChart JS Charts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.anychart.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\",\"name\":\"Shachee Swadia\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g\",\"caption\":\"Shachee Swadia\"},\"url\":\"https:\/\/www.anychart.com\/blog\/author\/shachee-swadia\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Error Chart and How To Create One in JavaScript HTML5","description":"Check out a stepwise guide for how to create a cool Error Chart using JavaScript. Visualizing COVID-19 threat perceptions of Democrats and Republicans.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/","og_locale":"en_US","og_type":"article","og_title":"Creating Error Chart in JavaScript","og_description":"Learn how to create a cool Error Chart using JavaScript. Visualizing COVID-19 threat perceptions of Democrats and Republicans.","og_url":"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2022-02-03T21:43:43+00:00","article_modified_time":"2022-08-13T11:08:39+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-javascript.png","type":"","width":"","height":""}],"author":"Shachee Swadia","twitter_card":"summary_large_image","twitter_title":"Creating Error Chart in JavaScript","twitter_description":"Learn how to create a cool Error Chart using JavaScript. Visualizing COVID-19 threat perceptions of Democrats and Republicans.","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-javascript.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Shachee Swadia","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/"},"author":{"name":"Shachee Swadia","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"headline":"Creating Error Chart in JavaScript","datePublished":"2022-02-03T21:43:43+00:00","dateModified":"2022-08-13T11:08:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/"},"wordCount":1249,"commentCount":1,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-js.png","keywords":["advanced data visualization","Americans","AnyChart","app development","best data visualization tool","best data visualization tools","chart design","chart development","chart examples","charts","coronavirus","coronavirus data","coronavirus data visualization","coronavirus pandemic","COVID-19","COVID-19 perception","COVID-19 threat","COVID-19 threat perception","COVID-19 vaccine","data analysis","data analytics","data analytics examples","data chart","data charting","data charts","data design","data graphics","data visual","data visualisation","Data Visualization","data visualization best practices","data visualization design","data visualization development","data visualization examples","data visualization practice","data visualization tutorial","data visualizations","data visuals","data viz examples","dataviz","dataviz examples","dataviz projects","Democratic Party","Democrats","design","error bars","error chart","front-end development","guest post","HTML","HTML charts","HTML5","html5 charts","infographics","interactive charts","interactive data visualization","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 technologies","js chart","js charting","js charts","JS graphics","Republican Party","Republicans","statistic visualization","statistical analysis","statistics","statistics visualization","Tips and tricks","tutorial","united states","vaccination","vaccine","vaccine skepticism","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\/02\/03\/error-chart-js\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/","url":"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/","name":"Error Chart and How To Create One in JavaScript HTML5","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-js.png","datePublished":"2022-02-03T21:43:43+00:00","dateModified":"2022-08-13T11:08:39+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"description":"Check out a stepwise guide for how to create a cool Error Chart using JavaScript. Visualizing COVID-19 threat perceptions of Democrats and Republicans.","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-js.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/error-chart-js.png","width":1450,"height":815},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/03\/error-chart-js\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Creating Error Chart in JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.anychart.com\/blog\/#website","url":"https:\/\/www.anychart.com\/blog\/","name":"AnyChart News","description":"AnyChart JS Charts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.anychart.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51","name":"Shachee Swadia","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g","caption":"Shachee Swadia"},"url":"https:\/\/www.anychart.com\/blog\/author\/shachee-swadia\/"}]}},"_links":{"self":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14503","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=14503"}],"version-history":[{"count":20,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14503\/revisions"}],"predecessor-version":[{"id":15514,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14503\/revisions\/15514"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=14503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=14503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=14503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}