Saturday, August 17, 2013

Using Google Charts in Caspio

When the Texas Education Agency released school accountability ratings late last week, we turned around in the same day a searchable database to compare results for Central Texas. We had started with a PDF report of pass/fail figures, so it was a bit of a challenge to get launched, but not anything new or noteworthy technically (though useful for parents of school children in Texas.)

Right as I was leaving that day, we found the data download for the full results that included individual scores on four specific indexes the TEA based their ratings on. I went back into the project this week and updated it to visualize those scores using Google Charts javascript library, which was a new effort. I'd used Google Charts as an image, but that's being deprecated.

There was one challenge worth sharing: My data often had blank values for schools that weren't rated for that value. When those blank values were returned into the chart (I choose the gauge to show the values), it would break all the javascript for all the charts. I didn't want to use zeros because I didn't want to show failing scores for schools that weren't really measured. So, I had to evaluate the value each time I used it as a variable, and then choose whether to build or ignore the gauge accordingly. This is not rocket science for a programmer, but it was something I hadn't done before.

In my edited code snippet below, which would show one gauge:
  • CI1 is variable I end up using from the Caspio record to build the chart.
  • CI1Value is a variable I use just to evaluate if CI1 is blank. If it is, I make CI1 an empty string so the rest of the page doesn't break. If it has a value, I change it to number and assign it to CI1.
  • CI1Cut and CI1CutValue are similar, but this is another value I pull from Caspio. It's the "passing" rate for that index.
  • The [@field:] code is where I'm calling the data from Caspio.
  • Lastly, at the bottom, I evaluate whether either CI1 or CI1Cut is a blank string, and if it is I skip writing out the div. Otherwise, it gets drawn and all is peachy.
I'm sure there is a better way to do this ... like I could probably write this without the CI1Value variable and just do those evaluations with CI1, but it worked, and that was important at the time.

There is a lot more to do with this data. I'd like to write the search results better so readers can more easily compare schools, and there are also lot of the tables and values that TEA uses to come up with the indexes that would be great detail for each school. I'll have to come back to it in the future.

  © Blogger template 'A Click Apart' by 2008

Back to TOP