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!
perl or ruby bindings
-
- Posts: 4
- Joined: Sat Mar 25, 2006 5:39 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.
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)
-
- Posts: 3
- Joined: Wed Apr 26, 2006 1:34 pm
Could you use this with Ruby on Rails?
Could you use this with Ruby on Rails? Any ideas?
It would be amazing if you could.
It would be amazing if you could.
-
- Posts: 4
- Joined: Sat Mar 25, 2006 5:39 am
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.
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.
-
- Posts: 2
- Joined: Sat Feb 09, 2008 2:15 pm
- Location: India