Update June 1, 2009: JavaFX 1.2 and later has charting functionality. See this post for details.
As I mentioned in the JFXtras: Utilities and Add-ons for the JavaFX Language post, JFXtras is an open-source project that helps fill in some of the gaps of the JavaFX 1.0 Release. There are several JavaFX developers actively creating functionality for this project, and Ben S. Jones, Director of Research & Development at The Standards Company is one of these developers. Ben has taken on the task of implementing charting and graphing capabilities in the JFXtras libraries so that any JavaFX program can easily create charts and graphs. He is currently working on a JavaFX implementation of a pie chart and has created a program, shown below, that demonstrates some of its features:
By the way, the graphical button in the upper right corner of the application shows and hides the Wedge Properties dialog shown above. Take the program for a spin by clicking on the Java Web Start Launch link above, and then read the brief explanation that follows, also written by Ben:
Bound in the Middle
"Given the trends in information interaction, application developers must
reach beyond simply displaying information and engage users with rich
data explorations. JavaFX addresses this shift in application
development with a powerful set of features for manipulating the
relationship between data and presentation. Of immediate benefit to
developers is the ability to leverage that relationship to quickly build
rich interfaces where users interact with data in meaningful ways.
As an example of this ability, the pie chart demo takes advantage of
dynamic binding relationships between data and presentation by means of
a simple interactive interface. Users add or remove wedges, change the
size, color, and label of a wedge, as well as alter other chart level
visuals. While simple in scope, it points to the growing blur between
traditional models of data production and consumption and the emerging
user expectation for information mashups.
For example, the techniques used in the demo to control the various
aspect of the chart work equally well in the creation, modification, and
re-conceptualization of the data. Starting with a simple sequence of
Numbers to hold explode values for each wedge, a slider control
dynamically manipulates elements in that sequence resulting in various
wedges pulling in or out from the center of the chart. Let's take a
quick look at how this can be coded, starting with the sequence holding
the explode values:
public var explodes:Number[];
and then the slider manipulating those values:
SwingSlider {
translateX:100
translateY:50
minimum: 0
maximum: radius / 5 as Integer
value: bind explodeValue with inverse
vertical: false
width:100
}
Notice that we did not bind the slider value to the explodes sequence directly. There are two reasons:
- explodes is a sequence of Number, not a single Integer as required by the SwingSlider value
- We want to manipulate specific elements in the sequence individually
This is where explodeValue comes into play. This intermediate bind value is extremely useful allowing a bi-directional flow of values between the slider and the explodes sequence. It also affords an opportunity to target specific wedges with these changing values. By defining explodeValue as follows:
var explodeValue:Integer on replace {
explodes[activeWedge] = explodeValue as Number;
};
we can link the current slider value to a specific wedge through the activeWedge index. In the case of the demo, activeWedge is set when a particular wedge has been clicked upon with the mouse. It could just as easily been set by some other action or changing data source. The wedge then explodes outward from the chart center or back inward depending on the value."
Thanks for this, Ben, and I look forward to seeing charting and graphing capabilities added to the JFXtras project!
By the way, if you are interested in using, or developing code for, the JFXtras project, please check it out!
Thanks,
Jim Weaver
JavaFXpert.com
Alberto,
This appears to occur occasionally on Vista systems. I'm looking into some modifications that should cure this issue. Thanks for your alert on the problem.
Posted by: Ben | February 13, 2009 at 03:56 PM
when I try to launch it I receive the following error (I have windows vista and Java 6 update 12):
com.sun.deploy.net.FailedDownloadException: Unable to load resource: http://javafx.standardsco.com/demos/piechart2d/Piechart2d.jar
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.javaws.LaunchDownload.downloadJarFiles(Unknown Source)
at com.sun.javaws.LaunchDownload.downloadEagerorAll(Unknown Source)
at com.sun.javaws.Launcher.downloadResources(Unknown Source)
at com.sun.javaws.Launcher.prepareLaunchFile(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.launch(Unknown Source)
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Posted by: Alberto | February 13, 2009 at 02:48 AM
"Would it be possible to publish the source code for this pie chart applet, Jim?"
It will be added at some point to the open source JFXtras project:
http://code.google.com/p/jfxtras/
Ben Jones is the developer working on charting/graphing, so you could join the project and ask him to see the source code.
Thanks,
Jim Weaver
Posted by: James Weaver | January 12, 2009 at 10:53 AM
Jim, no, I'm too occupied with my current project the next 10 weeks.
Would it be possible to publish the source code for this pie chart applet, Jim?
Regards, Tommy
Posted by: Tommy | January 12, 2009 at 10:40 AM