Permalink
Browse files

add in some code ro require jars.

also add an example.
  • Loading branch information...
1 parent 22bc2a4 commit 221618d07cfb7346b6888bd77e82f45ce1a85df2 @sundbp committed Mar 30, 2011
Showing with 150 additions and 11 deletions.
  1. +2 −0 .gitignore
  2. +5 −5 Gemfile
  3. +1 −1 LICENSE.txt
  4. +60 −5 README.md
  5. +55 −0 examples/pie_chart_demo_1.rb
  6. +27 −0 lib/rfreechart.rb
View
@@ -2,3 +2,5 @@ doc/
pkg/
Gemfile.lock
vendor/cache/*.gem
+.redcar/
+.yardoc/
View
10 Gemfile
@@ -1,11 +1,11 @@
source :rubygems
-gemspec
+#gemspec
group :development do
- gem 'rake', '~> 0.8.7'
- gem 'ore-tasks', '~> 0.4'
- gem 'rspec', '~> 2.4'
+ gem 'rake', '~> 0.8.7'
+ gem 'ore-tasks', '~> 0.4'
+ gem 'rspec', '~> 2.5'
gem 'kramdown'
- gem 'yard', '~> 0.6.0'
+ gem 'yard', '~> 0.6.0'
end
View
@@ -1,4 +1,4 @@
-Copyright (c) 2011 pts
+Copyright (c) 2011 Patrik Sundberg
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
@@ -1,26 +1,81 @@
# rfreechart
-* [Homepage](http://rubygems.org/gems/rfreechart)
+* [Homepage](https://github.com/sundbp/rfreechart)
* [Documentation](http://rubydoc.info/gems/rfreechart/frames)
## Description
-TODO: Description
+A simple jruby wrapper around the java library [jfreechart](http://www.jfree.org/jfreechart/).
+All it does is provide a structured way to require the jar files. The user refers to the java
+classes as usual (i.e. org.jfree.chart.ChartPanel).
-## Features
+Potentially some utilities to enhance productivity and make it more ruby friendly will be added
+later as well.
## Examples
- require 'rfreechart'
+This is an excerpts of examples/pie_chart_demo_1.rb:
+
+ class PieChartDemo1 < ApplicationFrame
+
+ def create_dataset
+ dataset = DefaultPieDataset.new
+ 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)
+ dataset
+ end
+
+ def create_chart(dataset)
+ chart = ChartFactory.createPieChart(
+ "Pie Chart Demo 1", # chart title
+ dataset, # data
+ true, # include legend
+ true,
+ false
+ )
+
+ plot = chart.getPlot()
+ plot.setSectionOutlinesVisible(false);
+ plot.setNoDataMessage("No data available");
+
+ chart
+ end
+
+ def create_demo_panel
+ chart = create_chart(create_dataset)
+ ChartPanel.new(chart)
+ end
+
+ def initialize(title)
+ super(title)
+ setContentPane(create_demo_panel)
+ end
+ end
+
+ demo = PieChartDemo1.new("Pie Chart Demo 1")
+ demo.pack()
+ RefineryUtilities.centerFrameOnScreen(demo)
+ demo.setVisible(true)
## Requirements
+* jfreechart jars
+* setting the environment variable **RFREECHART_JAR_PATH** as described below
+
## Install
$ gem install rfreechart
+Download and unpack [jfreechart](http://www.jfree.org/jfreechart/download.html), and
+set the environment variable **RFREECHART_JAR_PATH** to the path containg the
+jfreechar jars.
+
## Copyright
-Copyright (c) 2011 pts
+Copyright (c) 2011 Patrik Sundberg
See {file:LICENSE.txt} for details.
@@ -0,0 +1,55 @@
+$LOAD_PATH << File.dirname(__FILE__) + "/../lib"
+require 'rfreechart'
+
+java_import javax.swing.JPanel
+
+java_import org.jfree.chart.ChartFactory
+java_import org.jfree.chart.ChartPanel
+java_import org.jfree.data.general.DefaultPieDataset
+java_import org.jfree.ui.ApplicationFrame
+java_import org.jfree.ui.RefineryUtilities
+
+class PieChartDemo1 < ApplicationFrame
+
+ def create_dataset
+ dataset = DefaultPieDataset.new
+ 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)
+ dataset
+ end
+
+ def create_chart(dataset)
+ chart = ChartFactory.createPieChart(
+ "Pie Chart Demo 1", # chart title
+ dataset, # data
+ true, # include legend
+ true,
+ false
+ )
+
+ plot = chart.getPlot()
+ plot.setSectionOutlinesVisible(false);
+ plot.setNoDataMessage("No data available");
+
+ chart
+ end
+
+ def create_demo_panel
+ chart = create_chart(create_dataset)
+ ChartPanel.new(chart)
+ end
+
+ def initialize(title)
+ super(title)
+ setContentPane(create_demo_panel)
+ end
+end
+
+demo = PieChartDemo1.new("Pie Chart Demo 1")
+demo.pack()
+RefineryUtilities.centerFrameOnScreen(demo)
+demo.setVisible(true)
View
@@ -1 +1,28 @@
require 'rfreechart/version'
+
+require 'java'
+
+module Rfree
+
+ def self.jars
+ [
+ 'jcommon-1.0.16',
+ 'swtgraphics2d',
+ 'jfreechart-1.0.13',
+ 'jfreechart-1.0.13-swt',
+ 'jfreechart-1.0.13-experimental',
+ 'iText-2.1.5'
+ ]
+ end
+
+ Rfree.jars.each do |jar|
+ raise "You must set RFREECHART_JAR_PATH!" if ENV['RFREECHART_JAR_PATH'].nil?
+ begin
+ require File.join(ENV['RFREECHART_JAR_PATH'], jar)
+ rescue LoadError => e
+ STDERR.puts e.message
+ STDERR.puts "Make sure you have set RFREECHART_JAR_PATH to the path where your jfreechart jars are stored."
+ exit -1
+ end
+ end
+end

0 comments on commit 221618d

Please sign in to comment.