- An Area Chart displays quantitative data like a line chart but with the area between the line and the horizontal axis shaded. Good for comparing the magnitude of two or more series of data.
- The Bar Chart is a good way to show data in a way that makes it easy to see how the data changes over time or under a set of different conditions. The data is represented as rectangular area or, in the case of a 3D chart, a cubic volume whose height corresponds to the value of the data point being displayed.
- Bubble Charts plot data points on a 2-dimensional grid and have the extra ability to display the relative magnitudes of the data by controlling the diameter of the point (or bubble) displayed at each XY coordinate.
- A Line Chart is a simple way to display 2-dimensional data points where each point is connected to the next point in the data series by a line.
- Pie Charts are typically used to display the relative percentages of a series of values on a circle. The value of each piece of data, as a percentage of the total, dictates how much of the circle’s area it takes up. In other words, the chart shows how big a slice of the pie each value represents.
- The Scatter Chart is used to plot the points of one or more series of data. These charts are typically used to show the correlation (or not) of the data by comparing how the data points are clustered (or not).
Click the image to launch the demo
Common Chart Properties
The Chart abstract base class contains several public variables that are common to all charts. One such property that all charts share is a title. The following public variables in the Chart class control the style, position, and content of the title displayed on a chart.
- title is a String whose contents will be displayed as the title of the chart. Setting this variable to null or an empty string (its default value) causes the chart to be rendered without a title.
- titleFill controls the fill color of the title text. Since it is of type Paint, it can be a solid color as well as a linear or radial gradient.
- titleFont allows you to set the Font to be used to render the title text.
- titleGap is a Number that specifies the number of pixels to leave as a gap between the title and the content of the chart.
- titleSide is an enumeration that specifies which side of the chart the title will appear on. Its type is javafx.scene.chart.part.Side and its possible values are TOP, BOTTOM, LEFT, and RIGHT.
- legendGap is a Number that specifies the number of pixels to leave as a gap between the legend and the content of the chart.
- legendSide specifies which side of the chart the legend will appear on. Like titleSide, the possible values are TOP, BOTTOM, LEFT, and RIGHT.
- legendVisible is a Boolean value that controls whether the legend will be shown on the chart or hidden.
Stage { title: "Pie Chart" scene: Scene { content: [ PieChart { title: "What Is Your Favorite Pie?" titleFont: Font { size: 24 } data: [ PieChart.Data { value: 21 label: "Pumpkin" } PieChart.Data { value: 33 label: "Apple" } PieChart.Data { value: 17 label: "Cherry" } PieChart.Data { value: 29 label: "3.14159" } ] } ] } }This chart is rendered as shown in the image below. Note that right out of the box, the charts have a modern look with lighting and shading effects baked right in. You can also see that by default the title appears at the top of the chart. If you prefer a more 3-dimensional look to your pie charts, you can use the PieChart3D class instead of a PieChart. Everything in the listing above (aside from the class name) can remain the same and the result will have the appearance of a 3-dimensional disk instead of a circle. That concludes this entry. In the next entry, I'll continue this excerpt by taking a closer look at XYCharts.
Great article, great demo. Thank you, Dean.
ReplyDeleteThe demo produces this error on Mac OS X 10.5.7 with J2SE 5.0 on 32-bit Intel:
ReplyDeleteAn error occurred while launching/running the application.
Title: ChartDemo
Vendor: dean
Category: Download Error
Bad MIME type returned from server when accessing resource: http://idisk.mac.com/driverson/Public/jnlp/ChartDemo.jnlp - null
JNLPException[category: Download Error : Exception: null : LaunchDesc: null ]
at com.sun.javaws.cache.DownloadProtocol.doDownload(DownloadProtocol.java:656)
at com.sun.javaws.cache.DownloadProtocol.isLaunchFileUpdateAvailable(DownloadProtocol.java:819)
at com.sun.javaws.LaunchDownload.getUpdatedLaunchDesc(LaunchDownload.java:135)
at com.sun.javaws.Launcher.downloadResources(Launcher.java:1037)
at com.sun.javaws.Launcher.handleApplicationDesc(Launcher.java:378)
at com.sun.javaws.Launcher.handleLaunchFile(Launcher.java:218)
at com.sun.javaws.Launcher.run(Launcher.java:165)
at java.lang.Thread.run(Thread.java:613)
Patrick,
ReplyDeleteIs the error repeatable? I'm wondering if it's just Apple's servers being flaky or a real problem on 32-bit Macs. I know it works on 10.5.7 with 64-bit Macs (what I'm running). Unfortunately, I don't have access to a 32-bit platform at the moment.
Dean
Can I use this Chart API in normal Java program too?
ReplyDeleteDean, great article! Are the Chart examples included within the ebook pre-release (Alpha Book) of the Pro JavaFx Platform book?
ReplyDeleteTom
@tsjung75: There has been some work done in the latest version of JFXtras by Jim Clark to embed a JavaFX scene in a JComponent. Generally speaking, it's much easier to embed Java in a JavaFX program though.
ReplyDelete@Tom All examples from the book will be released when the book is finished. Probably some time in the next two weeks I would guess.
Dean,
ReplyDeleteYes, the problem is repeatable on my 32-bit Intel Mac. But the demo works fine on my Debian 5.0 Linux and Windows XP machines. I do not have a 64-bit Mac. Cleaning both my browser and Web Start caches did not help. I'm guessing that Apple should set the MIME type for .jnlp files to "application/x-java-jnlp-file" on their idisk.mac.com servers so my old J2SE 5.0 Web Start can recognize them. It would be even better if Apple updated Java on 32-bit Intel Macs to SE 6.
Patrick
Has anyone looked at dynamic charts?
ReplyDeletehttp://forums.sun.com/thread.jspa?threadID=5390747&tstart=0
This comment has been removed by the author.
ReplyDelete"Unable to launch the application." on Windows7RC with JDK 6 Update 14 installed.
ReplyDeleteStacktrace;
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: com/sun/javafx/runtime/Main
at com.sun.javafx.runtime.main.Main.main(Main.java:35)
... 9 more
Caused by: java.lang.ClassNotFoundException: com.sun.javafx.runtime.Main
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 10 more
Apple's Java for Mac OS X 10.5 Update 4 fixes the problems that I reported above. I can run the demo from the command line like this:
ReplyDeletejavaws ~/Desktop/ChartDemo.jnlp
Unfortunately, the update removes the ability to launch Web Start from the Finder. So the command line is the only way to run jnlp files. Clicking on a Web Start file annoyingly opens it in Dashcode. I assume this problem is only on 32-bit Intel Macs.
After installing Java for Mac OS X 10.5 Update 4, Java Web Start.app an be found in /System/Library/CoreServices/
ReplyDeleteTo restore correct Web Start behavior, do a Get Info on any jnlp file and choose to open it with the Java Web Start.app
The demo on this web page will then launch when clicked! :)
The charts look fine, but is there a support for using date axis? All the examples use number axis, and the API doesn't look to contain support for date.
ReplyDeleteAny ideas?
I particularly like any form of UML class diagrams to explain the relationship between classes.
ReplyDeleteThanks!
Rob Wilson.
ntimesc
ReplyDeletewhere can i get the source code of this chardemo.jnpl .... plz ???
The code is available on the jfxtras.org community site along with all of the other examples from the book:
ReplyDeletehttp://jfxtras.org/portal/pro-javafx-platform/-/asset_publisher/1Bl5/content/15695?redirect=%2Fportal%2Fpro-javafx-platform
I am new to JavaFX. our requirement is how to embed JavaFX charts in a Java Web Application.To be precise,How to use JavaFX charts in a web based Business Intelligence(BI) report/dashboard.I was trying to achieve since last 3days.Any help will be appreciated.
ReplyDeleteThanks in advance
I just work with charts in JavaFX. They are impressive, but I don't know how to export chart to a bitmap and save it as a file. Is it possible? It is very important fo me. I tried to find an answer in web and in books bot... nothing.
ReplyDeleteHello..
ReplyDeleteI am new to JavaFX. is it possible to pass a HashMap/ArrayList to JavaFX from Javascript???
Thanks in advance
how did u display gridlines in the background of each chart.
ReplyDeletecan u post some sample piece of code.
thanks
uday
When I use JFXtras to embed the charts into a swing JComponent, the charts lose all layout. The chart width and heights are always correct but all the chart content is smushed up into the corner of the scene with no width and height. Did you happen to try to put the ChartDemo into a swing component?
ReplyDeletenice but not much use for me ... no DateAxis !!!
ReplyDeletewait and see , maybe FX 3.0