Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Groovy JFreechart builder, working on java.net's groovychart.

DZone's Guide to

Groovy JFreechart builder, working on java.net's groovychart.

· Java Zone
Free Resource

Just released, a free O’Reilly book on Reactive Microsystems: The Evolution of Microservices at Scale. Brought to you in partnership with Lightbend.

Here is an update to the groovy JFreeChart implementation.

I've decided after a lot of prototyping and experimenting to go with the groovychart implementation on java.net as the base to move forwards from. This implementation is already quite complete, and actually after a bit of refactoring its starting to look quite promising.

Currently, I'm still having problems getting developer access to the groovychart project at java.net. This means that I have taken a snapshot of the code from CVS and am working on that codebase. I've sent out several emails and requests so hopefully that will change soon; as I have nowhere to centrally share the source. Once I get a reply from java.net or host elsewhere I will update this post. Suggestions are most welcome..

In terms of looks, my current example may look like a step backwards if you remember my last presentation, but bear in mind that I have not had time to tidy up the edges yet. Also bear in mind that this chart was built using the groovychart builder, which supports a good percentage of JFreeCharts functionality already.

Here's an example of the source for a pie chart:

import net.java.dev.groovychart.chart.ChartBuilder
import groovy.swing.SwingBuilder
import java.awt.BorderLayout as BL
import javax.swing.JFrame
import java.awt.Color
import java.awt.Dimension
import org.jfree.chart.ChartPanel

ChartBuilder cb = new ChartBuilder();
def pieChart = cb.piechart3d(title: "Simple Pie Chart") {
defaultPieDataset {
Series1(40.0f)
Series2(30.0f)
Series3(30.0f)
}
antiAlias = true
backgroundPaint(Color.WHITE)
}

def sb = new SwingBuilder()
def fr = sb.frame( title : 'Simple Pie Chart', size:[600, 400],
defaultCloseOperation: JFrame.EXIT_ON_CLOSE) {
widget(new ChartPanel(pieChart.chart), constraints: BL.CENTER)
}
fr.pack();
fr.show();

And the above code produced this image:

GroovyChart example

 

Other notes

  • At the moment there is a slight flaw in the number of slices, I'm working on this..
  • Currently I cannot get write access to groovychart's CVS, therefore the source for above is not yet available. Once this changes I will commit.
  • Bear in mind that this is still a prototype and may take some time to productionize.

Strategies and techniques for building scalable and resilient microservices to refactor a monolithic application step-by-step, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}