How to Create a Javascript Speedometer

Posted on April 13th, 2007 by tom.
Categories: Javascript, Tech.


This is just a simple PoC of a Javascript speedometer for a colleague of mine.

At first I thought that a speedometer would be terrible for visualizing data, but after playing around with it for a while, I can see it could have uses where the minimum and maximum are known and you just want to be able to determine at a glance what the current status is.

A speedometer like visualization could also be useful if you are using something like Comet and the data is rapidly changing. I've included a digital readout1, however you'll notice that with the high frequency of updates in the PoC it's not particularly easy to read compared to the speedo.

Firefox and Opera appear to be doing The Right Thing™ in term of caching the various images for the needle position, but I'm not so sure about IE. In both IE 6 and 7 you'll notice in the status bar that it will repeatedly report that it's downloading the same image and the needle blanks-out while loading far too often. You should be able to fix this by using Javascript to pre-fetch all the needle images.

000.0 km/h

BTW, sorry about the programmer art :/

If you find this useful, feel free to use the code and images as you like:

  1. Primarily for accessibility reasons [back]

12 comments.

  1. Ronn
    Comment on May 12th, 2007. Reply

    The code

  2. Ronn
    Comment on May 12th, 2007. Reply

    000.0 km/h

    Start Speedo

  3. Comment on May 13th, 2007. Reply

    Hi Ronn, I think WordPress truncated your comments. Could you try again?

  4. Ronn
    Comment on May 15th, 2007. Reply

    what is the code script of these speedklok can you script emailen

  5. Comment on May 23rd, 2007. Reply

    Hi Ronn, The code is in the zip file above.

  6. Ronn
    Comment on May 23rd, 2007. Reply

    Yes that to see I.. But what is script which you must use to get it active..

    Ronn:)

  7. Comment on May 23rd, 2007. Reply

    Hi Ronn, there is an option in the browser to view the source of a page…

    <script src="/wp-content/uploads/2007/04/speedo.js" type="text/javascript"></script>
    <div class="speedo" style="background: transparent url('/wp-content/uploads/2007/04/speedo.gif') repeat scroll 0% 50%; width: 260px; height: 210px"><div id="speed" style="background: transparent url('/wp-content/uploads/2007/04/0.gif') repeat scroll 0% 50%; overflow: hidden; width: 260px; height: 50px; padding-top: 160px; text-align: center; font-family: monospace; color: white">000.0 km/h</div></div>
    <button onclick="startSpeedo();" id="speedoControl">Start Speedo</button>

  8. Comment on May 26th, 2007. Reply

    :) thank Tom.. EN

    :) bedankt Tom.. NL

    1. Salam
      Comment on August 6th, 2007. Reply

      the speedometer sample does not show any output only the background image is visible wherease the needle does not appear visible could u please explain the reason

      1. Comment on August 8th, 2007. Reply

        Looks like I broke it at some stage. Until I have a chance to fix it, just use the zip file and the code above to embed.

  9. Salam
    Comment on July 17th, 2007. Reply

    Can anybody tell how to run the speedometer script in a jsp page?

    1. Comment on July 17th, 2007. Reply

      Just include the html listed above in the reply to Ronn in your JSP page.

Leave a comment

Names and email addresses are required (email addresses aren't displayed), url's are optional.

Comments may contain the following xhtml tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>