Archive for the ‘JavaScript’ Category

Charts and graphs and stuff

Monday, December 10th, 2007

It’s funny how things come in droves.

A good friend of mine has, over the years, written a few applications that require graphing. He has written them as VB applications and when I’ve suggested he make them as web-apps, one of his fairly valid objections is that it would be tricky to create good-looking graphs with dynamic data.

Google’s Charting API

So just this morning, the Barnacle drew my attention to Google’s new Charting API (Read the Developers’ Guide). It takes some query string parameters and returns your chart as an image.

Check it out:

Line chart with unevenly spaced data points and lines in red, green and dashed blue

Line chart with a pale blue horizontal band stretching from 25 percent to 75 percent of the way up the y-axis and a thin horizontal line ten percent of the way up the x-axis Three dimensional pie chart with May, June, July, August, September and October labels for each segment

Now that’s pretty cool, isn’t it?
Although I think the data encoding, while clever, seems a little quirky.

Flot for jQuery

And so having spotted that this morning, I’m stumbling around the net this evening and discover Flot, a charting plug-in for jQuery. This is teh awesome; just check out the examples, especially the zoom!

So, while you’re waiting for other browsers to support SVG, here’s a veritable choice of quality charting goodness to satisfy the most particular of needs.

IE: How to properly destroy your ’select’ elements with innerHTML!

Tuesday, October 2nd, 2007

I know that some people, myself included, say that you’re not supposed to use innerHTML.
And yet for expediency’s sake, I find myself using innerHTML.

Problem

I’ve got an AJAX request to a JSP page which in turn performs an XSL transform on an XML file and returns a bunch of HTML <option> elements that JavaScript inserts into an existing <select> element using innerHTML.

Firefox does it fine, as you’d expect, but IE wasn’t playing nice. The resultant markup was broken, with a missing first opening <option> tag, and some random empty <option> element on the end.

In short, nothing showed up.

Solution

So I turned to google and found: BUG: Internet Explorer Fails to Set the innerHTML Property of the Select Object.

Thanks Microsoft, you just make it so easy. Not even.

I think the best solution here is to do it properly, and change my JSP to return a JSON object or something, and use createElement instead. I know innerHTML is faster, but it’s kinda not proper.

How I discovered ‘cloneNode’

Wednesday, September 26th, 2007

So I was trying to copy all the <option></option> elements from one <select></select> element to another.

I had a drop-down list of countries, and I wanted users to be able to select more than one country, so had a ‘Add another country’ button that created a new drop-down; copying into it the <option></option> elements from the first drop-down. (more…)

JS vs. IE; round two.

Friday, July 20th, 2007

So I learned (the hard way) that IE doesn’t like it when you create JS variables with the same name as the id of an element in the code.

Thanks, Stuart.

Irksome: Internet Explorer vs. JavaScript

Monday, July 16th, 2007

So I’m coding a form and I want the user to be able to add more rows to it, if they wish.

So when the user activates a control, I use JS to create some ‘input’ elements (including some radio buttons), add a few attributes to them, and then insert them in a table cell.
It’s not exactly rocket science, even for a JS |\|00|3 such as myself.

Let me expand on this.

(more…)