Forum OpenACS Development: ploting service

Collapse
Posted by Rafael Calvo on
Hi,

One of my students has to build a package to plot time series. I am
thinking that this should be a service that other OACS packages should
use (e.g. the clickstream analysis or sales trends in the ecommerce
package).
It would probably be good to integrate another existing GPL package
but the ones I found are all in Java.The best found so far seems to
be: http://www.object-refinery.com/jfreechart/index.html but I don't
know how easy it would be to integrate it. But first what does people
think about using something like this?
Any recommendations?

Collapse
Posted by Cheng-Yi Hsu on
Visual Mining
Corda Technologies

They are java-based, can generate png/gif/jpg/flash/svg .... on the fly, and provide pretty fancy drill down function. For aolserver/tcl combo, you can call by file or generate dynamic javascript to output chart. Another way is use nsjava to integrate the package, but I don't know how to use nsjava .

Collapse
Posted by Jun Yamog on
Hi Rafael,

You can try tgchart or something.  Forgot its name.  I know Rob Locke used this once for one of our project.  You can also search the bboard about it.

Collapse
Posted by Tilmann Singer on
Maybe you want to check out those: nsgd, ino_chart

I found reportlab quite useful to produce pdf's and allegedly it is able to produce charts as well, so you might want to check that out too (search this forum for reportlab). I would guess that it can output to image formats as well as pdf, but I am not sure.

And then there is still the very simple but working approach of a 1x1 gif that gets extended by the <img size> tags ... I think there was an API to produce bar charts in that way in OpenACS 3.x.

Collapse
Posted by Dan Wickstrom on
Rafael,

I tried using jchart with nsjava and it seems to work okay. I ran a couple of demo programs as follows:

package require nsjava

# import the demo classes
nsjava::import -package com.jrefinery.chart.demo ImageMapDemo1 ImageMapDemo2

# main routines expect a string array arg - but it is not used so pass 0-length
# array
set args [nsjava::new {String[]} 0]

# call the two image demo routines
nsjava::call ImageMapDemo1 {main String[]} $args
nsjava::call ImageMapDemo2 {main String[]} $args


Which resulted in the following two .png images being created:

Barchart

Piechart

To enable nsjava to use the jchart software, it was only necessary to include the appropriate .jar files in the class path:


ns_section "ns/server/${server}/module/nsjava"
        ns_param   ClassPath  "/export/local/aolserver/bin/nsjava.jar:/home/unix/wickstrom/web/jchart/jfreechart-0.9.2/jars/jcommon-0.6.4.jar:/home/unix/wickstrom/web/jchart/jfreechart-0.9.2/jars/jfreechart-0.9.2.jar:/home/unix/wickstrom/web/jchart/jfreechart-0.9.2/jars/jfreechart-0.9.2-demo.jar"


If you try this, you should note that the demo programs don't give an absolute path for writing the .png files, so they will be created in the aolserver start directory. For actual use, you could pass in a tmpfile name and the data that you want plotted.

Collapse
Posted by Roberto Mello on
Dan, that looks pretty good.

I've uploaded Tcl GDChart to new-file-storage: . The file storage folder (which for some reason doesn't show up under the root shared tree is this: https://openacs.org/new-file-storage/one-folder.tcl?file_id=418.

It works pretty good. I load it with the Tcl "load" command because I can never figure out how to get 'package require' working in AOLserver (ugh).

Here's a graph I created with it and the code I used to do it (BTW, this is a real application, but the data used to generate this graph is completely ficticious):
Graph

# A db_multirow was omitted for brevity's sake

# Put totals and labels into list to generate graph, if requested
set labels [list "Grade
School" "Elementary
School" "Junior
High" "Senior
High"]
set totals [list $grade_total $elementary_total $junior_total $senior_total]

#
# If the user requested graphs, generate them
#

if { [info exists graph] && $graph == "on" } {

    load [ad_parameter PathToTgdchart]

    # Set file names
    set date [ns_fmttime [ns_time] "%Y-%m-%d-%T"]
    set path [string range [ad_conn file] 0 [string last / [ad_conn file]]]

    set gr [gdchart create 400 300]
    set graph_data [list]

    # Set Title and other details
    gdchart title $gr "$page_title
$level_blurb
$dateblurb
" 0x000000 giant
    gdchart bgcolor $gr 0xFFFFFF
    gdchart type $gr 3dpie
    set colors [sds_color_list [llength $labels]]
    gdchart datacolor $gr $colors
    gdchart edgecolor $gr "0x000000"

    gdchart labeldist $gr 20
    gdchart labelline $gr TRUE
    gdchart border $gr all

    # Output this image to a file
    regsub -all -- " " $page_title "_" page_title_no_spaces
    set fname "${path}png/${page_title_no_spaces}-${date}-${login_user_id}.png"
    set fname_nopath "${page_title_no_spaces}-${date}-${login_user_id}.png"

    gdchart file $gr $fname
    gdchart hold $gr destroy
    gdchart generate $gr true

    lappend graph_data $labels
    lappend graph_data $totals

    gdchart getchart $gr $graph_data

    # Blow away our chart handle and the image as well.
    gdchart delete $gr
}

ad_return_template

Collapse
Posted by Cheng-Yi Hsu on
We use nsgd to create trend/pie/pareto/histogram chart, here is the example:

you can find the source code at Here

Collapse
Posted by Rafael Calvo on
Thanks all!
these are great solutions
Collapse
Posted by Cheng-Yi Hsu on
Dan,
I nsgd, I can return use gd returnPNG $im to return image to web client, you don't need to generate a file on file system, do you have any example for nsjava/jfreechart servlet method ?
Collapse
Posted by Dan Wickstrom on
The interface between tcl and java treats everything like null-terminated strings, so this wouldn't currently work in nsjava/freechart. But that's a good point. I'll add it to my todo list to support passing binary data to/from tcl.

One other thing to note, nsjava does not support servlets. Instead it is a tcl extension module that allows the scripting of java components from tcl. Currently it provides a tcl api to perform the following functions in tcl:

  • Create instances of Java Objects from Tcl
  • Invoke instance methods on a java object from Tcl
  • Invoke methods on java array objects from Tcl
  • Invoke java static methods from Tcl
  • Get and Set Java Field values from Tcl
  • Determine if an Tcl Object is an instance of a Java Class
  • Introspect java objects from Tcl
  • Throw and Catch Java exceptions from Tcl
  • Lock and Unlock Java objects so that they aren't garbage collected
  • Import and un-import java classes to/from Tcl
  • Full access to aolserver database api from within user-defined java classes