Project

flotr

0.0
No commit activity in last 3 years
No release in over 3 years
Flotr (pron. like "plotter") is a Ruby plotter via flot.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 2.6.4
 Project Readme

Introduction

Flotr (pron.: like "plotter") is a plot/chart facility to be used within Ruby.

It is intended to be as portable as possible, and is thus aimed to generate HTML plots thanks to the great flot library.

Installation

Flotr gem has moved to Gemcutter. In order to install you have two alternative choices:

  1. Simply add the Gemcutter repo to your rubygem source list:

     gem sources -a http://gemcutter.org
    
  2. Install gemcutter:

     sudo gem install gemcutter
     sudo gem tumble
    

Next, simply install the gem:

sudo gem install flotr

Usage

The following code produces the flotr.html file located in the current folder:

require "rubygems"
require "flotr"
# Create a new plot
plot = Flotr::Plot.new("Test plot")

# Create two empty series
sin = Flotr::Data.new(:label => "Sin(x)", :color => "red")
cos = Flotr::Data.new(:label => "Cos(x)", :color => "blue")

# Push data into the two series
100.times do |i| 
  sin << [i, Math::sin(Math::PI / 100 * i)]
  cos << [i, Math::cos(Math::PI / 100 * i)]
end

plot << sin << cos
plot.show

At the moment, the Flotr::Plot.show method automatically opens the plot within a browser window under OS X and Windows. On other platforms (Linux) you have to open the generated file by hands.

The default template (since v1.3) allows zooming the plot. Reload the page to reset to full view.

Templates

Flotr uses templates for formatting the plots. Currently there are the following templates available:

  1. interacting: a simple layout that shows point coordinates on mouse hover
  2. zooming: a smaller overview is added on the right side of the main plot, allowing zooming of different plot areas

The current template can be selected as follows (amongst those installed by default):

p = Flotr::Plot.new
p.std_template                  #=> "zooming"
p.std_templates                 #=> ["interacting" , "zooming"]
p.std_template = "interacting"
p.std_template                  #=> "interacting"

Custom templates can be selected this way:

p.template = "full/path/to/template.rhtml"

Look within lib/*.rhtml for template examples. Templates follow the Erubis syntax.

Example

Obligatory example

Thanks to

The author of jflot, Ryan Funduk