Client-side GChart 2.0 adds support for pie, line, and area charts,
baseline-based bar charts, and more:
http://gchart.googlecode.com
With this release, GChart supports all the basic chart types while
remaining an Apache-licensed, 100% pure GWT-Java library without
requiring JSNI, browser plug-ins, or server round trips.
Below I'll share some technical aspects of GChart 2.0's implementation
I hope you'll find interesting.
* Squaring the Pie Slice
Some of you may recall the original GChart 1.1 post/discussion:
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/1b14846ee6b91f41/a2ba97266f2fe041?#a2ba97266f2fe041
Reading this, you may wonder how I ended up implementing pie slices
and arbitrary angled connecting lines. Did I use the "transparent
border triangle trick" and/or clever algorithms from
walterzorn.com?
Though I tried to use these, I reverted to something a lot simpler:
dotted connecting lines and banded-filled pie slices. Two new Symbol
class properties, fillSpacing and fillThickness, let you control the
spacing of the dots/bands and their size/thickness.
Though this approach means you may sometimes have to choose between
visual chart quality and speed, these new properties make it easy for
you to control this tradeoff. Besides, I like to think that dotted
connecting lines and banded fill pie slices really don't look all that
much worse than the solid fill variety. But then again, I could never
understand why no one ever used square pie charts...
In any case, the whole point of GChart is to layer the chart on top of
standard GWT Widgets, so, since those Widgets can only really draw
rectangles efficiently, I decided to make a virtue of necessity and
whole-heartedly embrace this dotted/banded look.
* CSS Convenience Methods: A cure for "CSS anxiety disorder"?
For many months I suffered from "CSS anxiety disorder": a condition
arising from one's desire to use CSS to specify an attribute (and thus
conform to a GWT best practice) while simultaneously wanting the same
property in the Java API (so that it would not be unnaturally
segregated from closely related features).
To address this (possibly imaginary) problem, the GChart 2.0 Java API
includes "CSS convenience methods" that can (optionally) override
traditionally CSS-based attribute specifications for certain selected
CSS attributes.
To some, this may seem like a fine point, since you could easily do
the same thing via a GWT DOM class method call, but to me, once you
invoke a DOM method you are thinking of the GChart as an HTML element,
and for some usage scenarios, that just isn't logical.
For example, for some applications, the background color of a GChart
is mainly about how the color-scheme of the chart blends in with the
surrounding page, and for these applications a CSS-based specification
makes good sense. Yet, for other applications, it is mainly all about
how well background color matches with, say, with the pie slice
shading pattern. That is, in some cases, background color is better
viewed as a feature of the GChart considered as a Java object
independent of its connection to any web page. So why can't you just
call GChart.setBackgroundColor in such cases? With GChart, you can.
To assure that the two specification methods can exist harmoniously
together, GChart recognizes a special property value, GChart.USE_CSS,
which instructs GChart to stand aside and allow the traditional CSS
cascade to define the attribute. For all such "dual access" GChart
Java properties (which are simultaneously also CSS attributes),
USE_CSS is the default property value. This assures that you can use
CSS just as you would with a standard GWT Widget whenever it makes
more sense to control that attribute from the "GChart as HTML element"
perspective.
Thanks to these CSS convenience methods, I have attained inner peace
through Java/CSS redundancy. I recommend the same treatment for anyone
else suffering from "CSS anxiety disorder". See the GChart.USE_CSS
javadoc comment for more information.
The following post by Peter Blazejewicz (thanks!) provided key
insights and a valuable Adobe Flex link that finally allowed me
resolve this problem to my satisfaction:
http://groups.google.com/group/Google-Web-Toolkit/msg/d8db5c7d56929c38
* GAME (GWT Ant Macros for Eclipse)
GChart 1.1 used an interactive build from Eclipse. GChart 2.0 is the
first version to use an ant-based build, as recommended to me by Ian
Petersen (
http://roughian.com) and Isaac Truett in this thread:
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/e59ca3641ad2888f/39a1ac1184e81dd6?#39a1ac1184e81dd6
Not having used Ant before and being rather slow at transferring the
syntax of GWT compiler commands into the syntax required by ant, I
found the conversion very painful. Plus, I was aggravated by the
thought "since so many other GWTers have already done this, why do I
have to do it again?". So I tried to put what I learned from the above
post and looking at other ant based builds in various open source
projects into a small set of reusable ant macros, targeted at someone
making the Eclipse-to-ant transition for the first time, that you can
see here:
http://gchart.googlecode.com/svn/trunk/gchart/game.xml
And here's the GChart ant build script that employs these macros:
http://gchart.googlecode.com/svn/trunk/gchart/build-gchart.xml
I gave these macros a name much more generic than their specialized
nature deserves--but perhaps someone will be inspired by that name to
create a really general set of such macros and distribute them as an
open source project or even as a facet of GWT's extended Eclipse-
supporting toolset. I would have used it, at least.
* Kudos to GWT
Reasonable people can disagree about if it makes sense to layer a
chart library on top of standard GWT Widgets. What is undeniable is
that doing such a project is a kind of "stress test" for the basic GWT
GUI infrastructure. It's the kind of test some other GUI libraries
I've used would have failed miserably, but that GWT passed so easily
that I almost forget to mention it.
Finally, thanks to the thousands of you who downloaded GChart 1.1 and
even more thanks to those of you who actually tried it and mentioned
it. I hope you like GChart 2.0
John Gunther