Forum OpenACS Development: Response to ploting service

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