perl or ruby bindings

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
mattismyname
Posts: 4
Joined: Sat Mar 25, 2006 5:39 am

perl or ruby bindings

Post by mattismyname » Sat Mar 25, 2006 5:43 am

Hi, sorry to say but I don't do Java. Anybody have any suggestions for how to use JFreeChart to generate charts from a Ruby or a Perl application? I've searched the forums but can't seem to find anything.

Alternatively, if anyone knows of good plotting & charting packages for these languages, let me know.

thanks!

mattismyname
Posts: 4
Joined: Sat Mar 25, 2006 5:39 am

Post by mattismyname » Mon Apr 24, 2006 12:03 am

Ok, I'll answer my own question in case anybody else out there has a need to do this. The easiest way I found to use jfreechart from a Ruby app was to use a Ruby<->Java bridge called YAJB (http://www.cmt.phys.kyushu-u.ac.jp/~M.S ... ?page=YAJB) This software allows instantiation and use of Java objects from a Ruby app.

As a PoC, I've ported PieChartDemo1 over to the Ruby language and it's working nicely.

Code: Select all

#!/usr/bin/ruby

require 'yajb/jbridge'
include JavaBridge

JBRIDGE_OPTIONS = {
		  :classpath => "jfreechart-1.0.1.jar:jcommon-1.0.0.jar", 
}

jimport "java.awt.*"
jimport "javax.swing.*"
jimport "org.jfree.chart.ChartFactory"                                                      
jimport "org.jfree.chart.ChartPanel"                                                        
jimport "org.jfree.chart.JFreeChart"                                                        
jimport "org.jfree.chart.plot.PiePlot"                                                      
jimport "org.jfree.data.general.DefaultPieDataset"
jimport "org.jfree.data.general.PieDataset"
jimport "org.jfree.ui.ApplicationFrame"                                                     
jimport "org.jfree.ui.RefineryUtilities" 

class PieChartDemo1 
	def initialize(title)
		@app_frame = jnew(:ApplicationFrame, title)
		@app_frame.setContentPane(createDemoPanel())
	end

	def pack()
		@app_frame.pack()
	end

	def setVisible(state)
		@app_frame.setVisible(state)
	end

	def createDemoPanel() 
		chart = createChart(createDataset())
		return jnew(:ChartPanel, chart)
	end

	def createChart(dataset)
		chart = :ChartFactory.jclass.createPieChart(
							"Pie Chart Demo 1",
							dataset,
							true,
							true,
							false )
		plot = chart.getPlot()
		plot.setSectionOutlinesVisible(false)
		plot.setLabelFont(jnew(:Font, "SansSerif", :Font.jclass.PLAIN, 12))
		plot.setNoDataMessage("No data available")
		plot.setCircular(false)
		plot.setLabelGap(0.02)
		return chart
	end

	def createDataset()
		dataset = jnew(:DefaultPieDataset)
		dataset.setValue("One", 43.2)
		dataset.setValue("Two", 10.0)
		dataset.setValue("Three", 27.5)
		dataset.setValue("Four", 17.5)
		dataset.setValue("Five", 11.0)
		dataset.setValue("Six", 19.4)
		return dataset;
	end

	def centerFrameOnScreen()
		:RefineryUtilities.jclass.centerFrameOnScreen(@app_frame)
	end

end

demo = PieChartDemo1.new("Pie Chart Demo 1")
demo.pack()
demo.centerFrameOnScreen
demo.setVisible(true)
sleep(60)

evilgeenius
Posts: 3
Joined: Wed Apr 26, 2006 1:34 pm

Could you use this with Ruby on Rails?

Post by evilgeenius » Wed Apr 26, 2006 1:35 pm

Could you use this with Ruby on Rails? Any ideas?

It would be amazing if you could.

mattismyname
Posts: 4
Joined: Sat Mar 25, 2006 5:39 am

Post by mattismyname » Wed Apr 26, 2006 6:40 pm

Using jfreechart with rails was my main motivation for doing this, so I surely hope it will work with rails. I have not yet tried it out yet. If anybody else has info or suggestions, please post!

FYI, I doubt the performance of this solution under rails will be very good since it requires firing up a JVM for each separate rails request which needs to generate a chart. But for a low volume app it seems like it will work very well.

khyatikabra
Posts: 2
Joined: Sat Feb 09, 2008 2:15 pm
Location: India

Post by khyatikabra » Sat Feb 09, 2008 2:18 pm

hi..

what if I want to use Perl instead of Ruby.. I dunno much about Ruby.. So will it be similar kind of code for using JFREEcharts.. or different.. And like 4 ruby.. is there a similar communciation facility between Perl and Java?

Can u plz elaborate....

thanks!

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Sun Feb 10, 2008 3:53 pm


khyatikabra
Posts: 2
Joined: Sat Feb 09, 2008 2:15 pm
Location: India

Post by khyatikabra » Sun Feb 10, 2008 4:18 pm

thanks!

Locked