{"id":6444,"date":"2024-01-11T16:40:00","date_gmt":"2024-01-11T16:40:00","guid":{"rendered":"https:\/\/codehim.com\/?p=6444"},"modified":"2024-01-22T14:44:03","modified_gmt":"2024-01-22T09:44:03","slug":"speedometer-code-in-javascript","status":"publish","type":"post","link":"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/","title":{"rendered":"Speedometer Code in JavaScript"},"content":{"rendered":"<p>This JavaScript code snippet helps you to create an animated speedometer to indicate speed. The speedometer display speed in both analog and digital format. The interface is inspired by the Tesla speedometer that is built with HTML5 canvas and JavaScript. You can set a custom speed and change the size of the speedometer according to your needs.<\/p>\n<h2>How to Create Speedometer in JavaScript<\/h2>\n<p>1. First of all, create a canvas element with an id &#8220;canvas&#8221; and place it where you want to display the speedometer.<\/p>\n<pre class=\"prettyprint linenums lang-html\">  &lt;canvas id=\"canvas\"&gt;&lt;\/canvas&gt;<\/pre>\n<p>2. After that, define the CSS styles for the canvas element as follows:<\/p>\n<pre class=\"prettyprint linenums lang-css\">canvas {\r\n  margin: 0 auto;\r\n  display: block;\r\n}<\/pre>\n<p>3. Finally, add the following JavaScript code and done.<\/p>\n<pre class=\"prettyprint linenums lang-js\">'use strict';\r\n\/*\r\n* TESLA HUD BY Tameem Imamdad timamdad@hawk.iit.edu\r\nGitHub: https:\/\/github.com\/tameemi\/tesla-speedometer\r\n*\/\r\n\r\nlet dev = false;\r\n\/\/let t0 = 0;\r\n\/\/let t1 = 0;\r\n\r\n     var c = document.getElementById(\"canvas\");\r\n        c.width = 500;\r\n        c.height = 500;\r\n\r\n        var ctx = c.getContext(\"2d\");\r\n\r\n        \/\/Rescale the size\r\n        ctx.scale(1,1);\r\n\r\n        var speedGradient = ctx.createLinearGradient(0, 500, 0, 0);\r\n        speedGradient.addColorStop(0, '#00b8fe');\r\n        speedGradient.addColorStop(1, '#41dcf4');\r\n\r\n        var rpmGradient = ctx.createLinearGradient(0, 500, 0, 0);\r\n        rpmGradient.addColorStop(0, '#f7b733');\r\n        rpmGradient.addColorStop(1, '#fc4a1a');\r\n        \/\/rpmGradient.addColorStop(1, '#EF4836');\r\n\r\n        function speedNeedle(rotation) {\r\n            ctx.lineWidth = 2;\r\n\r\n            ctx.save();\r\n            ctx.translate(250, 250);\r\n            ctx.rotate(rotation);\r\n            ctx.strokeRect(-130 \/ 2 + 170, -1 \/ 2, 135, 1);\r\n            ctx.restore();\r\n\r\n            rotation += Math.PI \/ 180;\r\n        }\r\n\r\n        function rpmNeedle(rotation) {\r\n            ctx.lineWidth = 2;\r\n\r\n            ctx.save();\r\n            ctx.translate(250, 250);\r\n            ctx.rotate(rotation);\r\n            ctx.strokeRect(-130 \/ 2 + 170, -1 \/ 2, 135, 1);\r\n            ctx.restore();\r\n\r\n            rotation += Math.PI \/ 180;\r\n        }\r\n\r\n        function drawMiniNeedle(rotation, width, speed) {\r\n            ctx.lineWidth = width;\r\n\r\n            ctx.save();\r\n            ctx.translate(250, 250);\r\n            ctx.rotate(rotation);\r\n            ctx.strokeStyle = \"#333\";\r\n            ctx.fillStyle = \"#333\";\r\n            ctx.strokeRect(-20 \/ 2 + 220, -1 \/ 2, 20, 1);\r\n            ctx.restore();\r\n\r\n            let x = (250 + 180 * Math.cos(rotation));\r\n            let y = (250 + 180 * Math.sin(rotation));\r\n\r\n            ctx.font = \"700 20px Open Sans\";\r\n            ctx.fillText(speed, x, y);\r\n\r\n            rotation += Math.PI \/ 180;\r\n        }\r\n\r\n        function calculateSpeedAngle(x, a, b) {\r\n            let degree = (a - b) * (x) + b;\r\n            let radian = (degree * Math.PI) \/ 180;\r\n            return radian &lt;= 1.45 ? radian : 1.45;\r\n        }\r\n\r\n        function calculateRPMAngel(x, a, b) {\r\n            let degree = (a - b) * (x) + b;\r\n            let radian = (degree * Math.PI) \/ 180;\r\n            return radian &gt;= -0.46153862656807704 ? radian : -0.46153862656807704;\r\n        }\r\n\r\n        function drawSpeedo(speed, gear, rpm, topSpeed) {\r\n            if (speed == undefined) {\r\n                return false;\r\n            } else {\r\n                speed = Math.floor(speed);\r\n                rpm = rpm * 10;\r\n            }\r\n\r\n            ctx.clearRect(0, 0, 500, 500);\r\n\r\n            ctx.beginPath();\r\n            ctx.fillStyle = 'rgba(0, 0, 0, .9)';\r\n            ctx.arc(250, 250, 240, 0, 2 * Math.PI);\r\n            ctx.fill();\r\n            ctx.save()\r\n            ctx.restore();\r\n            ctx.fillStyle = \"#FFF\";\r\n            ctx.stroke();\r\n\r\n            ctx.beginPath();\r\n            ctx.strokeStyle = \"#333\";\r\n            ctx.lineWidth = 10;\r\n            ctx.arc(250, 250, 100, 0, 2 * Math.PI);\r\n            ctx.stroke();\r\n\r\n            ctx.beginPath();\r\n            ctx.lineWidth = 1;\r\n            ctx.arc(250, 250, 240, 0, 2 * Math.PI);\r\n            ctx.stroke();\r\n\r\n            ctx.font = \"700 70px Open Sans\";\r\n            ctx.textAlign = \"center\";\r\n            ctx.fillText(speed, 250, 220);\r\n\r\n            ctx.font = \"700 15px Open Sans\";\r\n            ctx.fillText(\"mph\", 250, 235);\r\n\r\n            if (gear == 0 &amp;&amp; speed &gt; 0) {\r\n                ctx.fillStyle = \"#999\";\r\n                ctx.font = \"700 70px Open Sans\";\r\n                ctx.fillText('R', 250, 460);\r\n\r\n                ctx.fillStyle = \"#333\";\r\n                ctx.font = \"50px Open Sans\";\r\n                ctx.fillText('N', 290, 460);\r\n            } else if (gear == 0 &amp;&amp; speed == 0) {\r\n                ctx.fillStyle = \"#999\";\r\n                ctx.font = \"700 70px Open Sans\";\r\n                ctx.fillText('N', 250, 460);\r\n\r\n                ctx.fillStyle = \"#333\";\r\n                ctx.font = \"700 50px Open Sans\";\r\n                ctx.fillText('R', 210, 460);\r\n\r\n                ctx.font = \"700 50px Open Sans\";\r\n                ctx.fillText(parseInt(gear) + 1, 290, 460);\r\n            } else if (gear - 1 &lt;= 0) {\r\n                ctx.fillStyle = \"#999\";\r\n                ctx.font = \"700 70px Open Sans\";\r\n                ctx.fillText(gear, 250, 460);\r\n\r\n                ctx.fillStyle = \"#333\";\r\n                ctx.font = \"50px Open Sans\";\r\n                ctx.fillText('R', 210, 460);\r\n\r\n                ctx.font = \"700 50px Open Sans\";\r\n                ctx.fillText(parseInt(gear) + 1, 290, 460);\r\n            } else {\r\n                ctx.font = \"700 70px Open Sans\";\r\n                ctx.fillStyle = \"#999\";\r\n                ctx.fillText(gear, 250, 460);\r\n\r\n                ctx.font = \"700 50px Open Sans\";\r\n                ctx.fillStyle = \"#333\";\r\n                ctx.fillText(gear - 1, 210, 460);\r\n                if (parseInt(gear) + 1 &lt; 7) {\r\n                    ctx.font = \"700 50px Open Sans\";\r\n                    ctx.fillText(parseInt(gear) + 1, 290, 460);\r\n                }\r\n            }\r\n\r\n            ctx.fillStyle = \"#FFF\";\r\n            for (var i = 10; i &lt;= Math.ceil(topSpeed \/ 20) * 20; i += 10) {\r\n                console.log();\r\n                drawMiniNeedle(calculateSpeedAngle(i \/ topSpeed, 83.07888, 34.3775) * Math.PI, i % 20 == 0 ? 3 : 1, i%20 == 0 ? i : '');\r\n                \r\n                if(i&lt;=100) { \r\n                    drawMiniNeedle(calculateSpeedAngle(i \/ 47, 0, 22.9183) * Math.PI, i % 20 == 0 ? 3 : 1, i % 20 ==\r\n                    0 ?\r\n                    i \/ 10 : '');\r\n                }\r\n            }\r\n\r\n            ctx.beginPath();\r\n            ctx.strokeStyle = \"#41dcf4\";\r\n            ctx.lineWidth = 25;\r\n            ctx.shadowBlur = 20;\r\n            ctx.shadowColor = \"#00c6ff\";\r\n\r\n            ctx.strokeStyle = speedGradient;\r\n            ctx.arc(250, 250, 228, .6 * Math.PI, calculateSpeedAngle(speed \/ topSpeed, 83.07888, 34.3775) * Math.PI);\r\n            ctx.stroke();\r\n            ctx.beginPath();\r\n            ctx.lineWidth = 25;\r\n            ctx.strokeStyle = rpmGradient;\r\n            ctx.shadowBlur = 20;\r\n            ctx.shadowColor = \"#f7b733\";\r\n\r\n            ctx.arc(250, 250, 228, .4 * Math.PI, calculateRPMAngel(rpm \/ 4.7, 0, 22.9183) * Math.PI, true);\r\n            ctx.stroke();\r\n            ctx.shadowBlur = 0;\r\n\r\n\r\n            ctx.strokeStyle = '#41dcf4';\r\n            speedNeedle(calculateSpeedAngle(speed \/ topSpeed, 83.07888, 34.3775) * Math.PI);\r\n\r\n            ctx.strokeStyle = rpmGradient;\r\n            rpmNeedle(calculateRPMAngel(rpm \/ 4.7, 0, 22.9183) * Math.PI);\r\n\r\n            ctx.strokeStyle = \"#000\";\r\n        }\r\n\r\n\r\nfunction setSpeed () {\r\n  let speedM = 0;\r\n  let gear = 0;\r\n  let rpm = 0;\r\n   setInterval(function(){\r\n     if (speedM &gt; 160){\r\n        speedM = 0;\r\n        rpm = 0;\r\n      }\r\n     if (speedM &gt; 1 &amp;&amp; speedM&lt; 30){\r\n       gear = 1;\r\n     } else if (speedM &gt; 30 &amp;&amp; speedM &lt; 50) {\r\n       gear = 2;\r\n          } else if (speedM &gt; 50 &amp;&amp;   speedM &lt; 70) {\r\n       gear = 3;\r\n     } else if (speedM &gt; 70 &amp;&amp;   speedM &lt; 100)      {\r\n       gear = 4;\r\n          } else if (speedM &gt; 100)      {\r\n       gear = 5;\r\n     }\r\n     \r\n     speedM++;\r\n     if (rpm &lt; 1){\r\n      rpm += .03; \r\n     }\r\n        drawSpeedo(speedM,gear,rpm,160);\r\n\r\n   }, 40);\r\n  \r\n}\r\n\r\ndocument.addEventListener('DOMContentLoaded', function() {\r\n\r\n    \/\/setInterval(setSpeed, 2000)\r\n    \/\/renderCanvas();\r\n  setSpeed();\r\n    \/\/drawSpeedo(120,4,.8,160);\r\n}, false);<\/pre>\n<p>That&#8217;s all! hopefully, you have successfully integrated this speedometer code snippet into your project. If you have any questions or facing any issues, feel free to comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This JavaScript code snippet helps you to create an animated speedometer to indicate speed. The speedometer display speed in both&#8230;<\/p>\n","protected":false},"author":1,"featured_media":6463,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[116],"tags":[],"class_list":["post-6444","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vanilla-javascript"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Speedometer Code in JavaScript &#8212; CodeHim<\/title>\n<meta name=\"description\" content=\"Here is a lightweight JavaScript code snippet to create a speedometer with HTML5 canvas. You can view demo and download code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Speedometer Code in JavaScript &#8212; CodeHim\" \/>\n<meta property=\"og:description\" content=\"Here is a lightweight JavaScript code snippet to create a speedometer with HTML5 canvas. You can view demo and download code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"CodeHim\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codehimofficial\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-11T16:40:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-22T09:44:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/www.codehim-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"960\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Asif Mughal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodeHimOfficial\" \/>\n<meta name=\"twitter:site\" content=\"@CodeHimOfficial\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Asif Mughal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/\"},\"author\":{\"name\":\"Asif Mughal\",\"@id\":\"https:\/\/codehim.com\/#\/schema\/person\/cc48f1dbe072a89a62a98171b7db43ed\"},\"headline\":\"Speedometer Code in JavaScript\",\"datePublished\":\"2024-01-11T16:40:00+00:00\",\"dateModified\":\"2024-01-22T09:44:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/\"},\"wordCount\":137,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/codehim.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/www.codehim-2.png\",\"articleSection\":[\"Vanilla JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/\",\"url\":\"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/\",\"name\":\"Speedometer Code in JavaScript &#8212; CodeHim\",\"isPartOf\":{\"@id\":\"https:\/\/codehim.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/www.codehim-2.png\",\"datePublished\":\"2024-01-11T16:40:00+00:00\",\"dateModified\":\"2024-01-22T09:44:03+00:00\",\"description\":\"Here is a lightweight JavaScript code snippet to create a speedometer with HTML5 canvas. You can view demo and download code.\",\"breadcrumb\":{\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#primaryimage\",\"url\":\"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/www.codehim-2.png\",\"contentUrl\":\"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/www.codehim-2.png\",\"width\":1280,\"height\":960,\"caption\":\"Speedometer Code in JavaScript\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/codehim.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Vanilla JavaScript\",\"item\":\"https:\/\/codehim.com\/category\/vanilla-javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Speedometer Code in JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/codehim.com\/#website\",\"url\":\"https:\/\/codehim.com\/\",\"name\":\"CodeHim\",\"description\":\"Web Design Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/codehim.com\/#organization\"},\"alternateName\":\"Web Design Codes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/codehim.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/codehim.com\/#organization\",\"name\":\"CodeHim - Web Design Code & Scripts\",\"url\":\"https:\/\/codehim.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codehim.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/codehim.com\/wp-content\/uploads\/2023\/06\/Codehim-short-logo.jpg\",\"contentUrl\":\"http:\/\/codehim.com\/wp-content\/uploads\/2023\/06\/Codehim-short-logo.jpg\",\"width\":280,\"height\":280,\"caption\":\"CodeHim - Web Design Code & Scripts\"},\"image\":{\"@id\":\"https:\/\/codehim.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/codehimofficial\",\"https:\/\/x.com\/CodeHimOfficial\",\"https:\/\/www.instagram.com\/codehim\/\",\"https:\/\/www.linkedin.com\/company\/codehim\",\"https:\/\/co.pinterest.com\/codehim\/\",\"https:\/\/www.youtube.com\/@codehim\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/codehim.com\/#\/schema\/person\/cc48f1dbe072a89a62a98171b7db43ed\",\"name\":\"Asif Mughal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codehim.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b25bfcd7d4e341c2c6f785a88d8ad2a4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b25bfcd7d4e341c2c6f785a88d8ad2a4?s=96&d=mm&r=g\",\"caption\":\"Asif Mughal\"},\"description\":\"I code and create web elements for amazing people around the world. I like work with new people. New people new Experiences. I truly enjoy what I'm doing, which makes me more passionate about web development and coding. I am always ready to do challenging tasks whether it is about creating a custom CMS from scratch or customizing an existing system.\",\"sameAs\":[\"https:\/\/codehim.com\"],\"url\":\"https:\/\/codehim.com\/author\/asif-mughal\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Speedometer Code in JavaScript &#8212; CodeHim","description":"Here is a lightweight JavaScript code snippet to create a speedometer with HTML5 canvas. You can view demo and download code.","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:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Speedometer Code in JavaScript &#8212; CodeHim","og_description":"Here is a lightweight JavaScript code snippet to create a speedometer with HTML5 canvas. You can view demo and download code.","og_url":"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/","og_site_name":"CodeHim","article_publisher":"https:\/\/www.facebook.com\/codehimofficial","article_published_time":"2024-01-11T16:40:00+00:00","article_modified_time":"2024-01-22T09:44:03+00:00","og_image":[{"width":1280,"height":960,"url":"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/www.codehim-2.png","type":"image\/png"}],"author":"Asif Mughal","twitter_card":"summary_large_image","twitter_creator":"@CodeHimOfficial","twitter_site":"@CodeHimOfficial","twitter_misc":{"Written by":"Asif Mughal","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#article","isPartOf":{"@id":"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/"},"author":{"name":"Asif Mughal","@id":"https:\/\/codehim.com\/#\/schema\/person\/cc48f1dbe072a89a62a98171b7db43ed"},"headline":"Speedometer Code in JavaScript","datePublished":"2024-01-11T16:40:00+00:00","dateModified":"2024-01-22T09:44:03+00:00","mainEntityOfPage":{"@id":"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/"},"wordCount":137,"commentCount":2,"publisher":{"@id":"https:\/\/codehim.com\/#organization"},"image":{"@id":"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/www.codehim-2.png","articleSection":["Vanilla JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/","url":"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/","name":"Speedometer Code in JavaScript &#8212; CodeHim","isPartOf":{"@id":"https:\/\/codehim.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#primaryimage"},"image":{"@id":"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/www.codehim-2.png","datePublished":"2024-01-11T16:40:00+00:00","dateModified":"2024-01-22T09:44:03+00:00","description":"Here is a lightweight JavaScript code snippet to create a speedometer with HTML5 canvas. You can view demo and download code.","breadcrumb":{"@id":"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#primaryimage","url":"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/www.codehim-2.png","contentUrl":"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/www.codehim-2.png","width":1280,"height":960,"caption":"Speedometer Code in JavaScript"},{"@type":"BreadcrumbList","@id":"https:\/\/codehim.com\/vanilla-javascript\/speedometer-code-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codehim.com\/"},{"@type":"ListItem","position":2,"name":"Vanilla JavaScript","item":"https:\/\/codehim.com\/category\/vanilla-javascript\/"},{"@type":"ListItem","position":3,"name":"Speedometer Code in JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/codehim.com\/#website","url":"https:\/\/codehim.com\/","name":"CodeHim","description":"Web Design Code Snippets","publisher":{"@id":"https:\/\/codehim.com\/#organization"},"alternateName":"Web Design Codes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codehim.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codehim.com\/#organization","name":"CodeHim - Web Design Code & Scripts","url":"https:\/\/codehim.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codehim.com\/#\/schema\/logo\/image\/","url":"http:\/\/codehim.com\/wp-content\/uploads\/2023\/06\/Codehim-short-logo.jpg","contentUrl":"http:\/\/codehim.com\/wp-content\/uploads\/2023\/06\/Codehim-short-logo.jpg","width":280,"height":280,"caption":"CodeHim - Web Design Code & Scripts"},"image":{"@id":"https:\/\/codehim.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codehimofficial","https:\/\/x.com\/CodeHimOfficial","https:\/\/www.instagram.com\/codehim\/","https:\/\/www.linkedin.com\/company\/codehim","https:\/\/co.pinterest.com\/codehim\/","https:\/\/www.youtube.com\/@codehim"]},{"@type":"Person","@id":"https:\/\/codehim.com\/#\/schema\/person\/cc48f1dbe072a89a62a98171b7db43ed","name":"Asif Mughal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codehim.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b25bfcd7d4e341c2c6f785a88d8ad2a4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b25bfcd7d4e341c2c6f785a88d8ad2a4?s=96&d=mm&r=g","caption":"Asif Mughal"},"description":"I code and create web elements for amazing people around the world. I like work with new people. New people new Experiences. I truly enjoy what I'm doing, which makes me more passionate about web development and coding. I am always ready to do challenging tasks whether it is about creating a custom CMS from scratch or customizing an existing system.","sameAs":["https:\/\/codehim.com"],"url":"https:\/\/codehim.com\/author\/asif-mughal\/"}]}},"views":11045,"_links":{"self":[{"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/posts\/6444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/comments?post=6444"}],"version-history":[{"count":0,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/posts\/6444\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/media\/6463"}],"wp:attachment":[{"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/media?parent=6444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/categories?post=6444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/tags?post=6444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}