Over a million developers have joined DZone.

Charting with JFreeChart in Groovy.

· Java Zone

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

I’ve started looking into the possibility of wrapping up JFreeChart to make it a little groovier. I know there’s no end of web packages for graphing, but what if you don’t want to transmit sensitive data across the internet? What if you don’t want the data in the URL? What if the application in question is a Swing GUI thats not connected to the internet?

It's for all those situations that I have looked at wrapping up the excellent http://www.jfree.org/jfreechart API in a Groovy builder. My proposed name is FreeChartBuilder.

FreeChartBuilder is an early look at how a builder object using the state machine pattern could provide fairly complete support for the underlying Java API. The currently attached source archive gives an example of what can be achieved for pie and simple line charts.

Example of using the prototype source

import com.thecoderscorner.gfreechart.GFreeChartBuilder
import javax.swing.ImageIcon
import java.awt.Color
import groovy.swing.SwingBuilder
import javax.swing.JFrame
import java.awt.BorderLayout

def chart = new GFreeChartBuilder();

chart.createPie(title: "Pie Chart", legend: true, size: [400,200]) {
dataset {
antiAlias true
backgroundPaint Color.WHITE

plot {
sectionOutlinesVisible true
font name: 'arial', height: 15
labelGap 0.02
simpleGradient( start: new Color(0,0,255),
end: new Color(255,255,255) )

ImageIcon pieImg = chart.getIconImage()

def sb = new SwingBuilder()
def fr = sb.frame( title : 'Test Graph', size:[800,600],
defaultCloseOperation: JFrame.EXIT_ON_CLOSE) {
label(icon: pieImg, constraints: BorderLayout.CENTER)


..and the output of the above code:

chart produced by above source
 Right now you can look at the prototype source which I will update as I make progress
However, be aware it is a prototype, and not even close to production quality yet.


Reprinted from original blog entry at: http://www.thecoderscorner.com/blogEntry/show/16

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}