A Bar Graph Generator
Graphs are excellent ways to display visual information. You can create bar graphs by drawing them in Adobe Photoshop or by calculating them in Microsoft Excel, but for dynamic data that might need to change on a regular basis, why not have JavaScript do it instead on the fly? While we’ve said throughout this book that JavaScript is object-oriented (and therefore buzzword-compliant), and we’ve used objects throughout the book, we’ve only briefly shown you how to create your own custom objects. Here’s a more in-depth example of how objects work, as seen in Scripts 15.13 (HTML), 15.14 (CSS), and 15.15 (JavaScript).
To generate a bar graph:
1. | var radioButtons = document.getElementsByTagName("input"); for (var i=0; i<radioButtons.length;i++) ... |
Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.