Archive for July, 2007

How to Present Well (like Joe Gregorio)

Wednesday, July 25th, 2007

A nice tidbit from Joe’s talk at Oscon 2007:

Exposition: I can lie if you can learn

Stacked Bar Charts in JRuby using JFreeChart

Thursday, July 12th, 2007

I was getting some comments on a previous post asking about building stacked bar charts in JRuby using JFreeChart, so here’s another example:

# Mostly inspired by 
# http://left.subtree.org/2007/01/15/creating-sparklines-with-jfreechart/
# have JFreeChart in your classpath, obviously, as well as jcommon.jar
require 'java'

module Graph
  class StackedBar
    include_class 'java.io.File'
    include_class 'org.jfree.chart.ChartUtilities'
    include_class 'org.jfree.chart.JFreeChart'
    include_class 'org.jfree.data.category.DefaultCategoryDataset'
    include_class 'org.jfree.chart.ChartFactory'
    include_class 'org.jfree.chart.plot.PlotOrientation'

    def initialize(width=600, height=400, data=[])
      @width = width
      @height = height
      dataset = create_sample_data() if data.empty?
      @chart = create_chart(dataset)
    end

    def render_to_file(filename, format="png")
      puts "Rendering graph to #{filename}"
      javafile = java.io.File.new(filename)
      ChartUtilities.saveChartAsPNG(javafile, @chart, @width, @height)
    end

    private
    def create_sample_data
      dataset = DefaultCategoryDataset.new
      dataset.addValue(1, "Submitted", "A")
      dataset.addValue(1, "Assigned", "A")
      dataset.addValue(3, "In-work", "A")
      dataset.addValue(1, "InVerfication", "A")
      dataset.addValue(2, "Delivered", "A")
      dataset.addValue(2, "Submitted", "B")
      dataset.addValue(1, "Rejected", "B")
      dataset.addValue(1, "Closed", "B")
      dataset.addValue(1, "Submitted", "C")
      dataset.addValue(1, "Assigned", "C")
      dataset.addValue(3, "In-work", "C")
      dataset.addValue(2, "On-hold", "C")

      return dataset
    end

    def create_chart(dataset)
      chart = ChartFactory.createStackedBarChart("XYZ's Development Projects",
                                                 "Project Name", 
                                                 "Hours", 
                                                 dataset,
                                                 PlotOrientation::VERTICAL, 
                                                 true, 
                                                 true, 
                                                 false)
      return chart    
    end
  end # class StackedBar  
end # class Graph

sb = Graph::StackedBar.new
sb.render_to_file("stacked_bar.png")

Here’s the output:

Stacked Bar chart example

Code here: http://kfahlgren.com/code/stacked_bar.jrb

More Clever GMail Ads for Programmers

Tuesday, July 10th, 2007

Just like the folks from Jane Street Capital, Swivel really knows how to write good, eye-catching ad copy (for some crazy subset of the population):

Clever Swivel Rails Ad