DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:pchart

pchart plugin

Compatible with DokuWiki

2008-05-05

plugin Insert pChart graph in your DokuWiki pages

Last updated on
2008-09-03
Provides
Syntax
Conflicts with
stats

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to avbarchart

Tagged with chart, diagram, images, media

Description

With this plugin you can create pchart graphs. You can visit pChart web site for more information.

You can see the plugin in action here : Spéléo Club Vendée. This is the first Beta release.

Requirement

PChart need GD2, so you must install it on your PHP installation.

Syntax and usage

Usage

To invoke the plugin you must use this syntax : <pchart>chart_syntax</pchart>.

Chart name

The plugin create the chart in the same namespace of the page. By defaut, the chart name is pchart_*.png.

You can force chart name like that : <pchart name=a_wiki_media_name>chart_syntax</pchart>. Don't use extension png in the wiki media name!

Alignment

You can force alignment of chart with space like DokuWiki image :

  • <pchart>chart_syntax</pchart> standard alignment.
  • <pchart> chart_syntax </pchart> center alignment.
  • <pchart> chart_syntax</pchart> right alignment.
  • <pchart>chart_syntax </pchart> left alignment.

Rebuild and remove chart

Even, if you remove code from your page, the chart is not destroy and can be use like other image.

If you don't want to rebuild image each time your cache is restore, you must uncomment the if group lines :

//if (!@is_file($chartFullPath)) 
...
//}

Should be in a conf file for next release ;-)

But in this case, if you want to rebuild the chart, you must remove the chart with the media manager.

Chart syntax

The chart syntax use the : syntax separator, ; for series separator and . for decimal.

<pchart>chart_type:arg 1:…:arg n:serie 1:…:serie n</pchart>

chart_type is use to invoke the chart type, it should be like:

  • line,
  • cubic,
  • bar,
  • stackedbar,
  • limit,
  • radar,
  • or pie,

Then, argument and serie depend of the chart type.

arg define different single data for the graph, should be like :

  • Title : Set the title of the graph,
  • XLegend : Set the legend for the X axis,
  • XUnit : Set the unit for the X axis,
  • YLegend : Set the legend for the Y axis,
  • YUnit : Set the legend for the Y axis.

serie define array of values for the graph, should be like :

  • Legend Serie 1;…;Legend Serie n : Set legends for series for multi series chart.
  • Serie 1 val 1;…;Serie 1 val m : Set values for serie.
  • Axis 1 Legend;…;Axis m Legend : Set legends for axis for multi axis chart.

Line

<pchart>line:Title:XLegend:XUnit:YLegend:YUnit:Legend Serie 1;…;Legend Serie n:Serie 1 val 1;…;Serie 1 val m:…:Serie n val 1;…;Serie n val m</pchart>

Cubic line

<pchart>cubic:Title:XLegend:XUnit:YLegend:YUnit:Legend Serie 1;…;Legend Serie n:Serie 1 val 1;…;Serie 1 val m:…:Serie n val 1;…;Serie n val m</pchart>

Bar

<pchart>bar:Title:XLegend:XUnit:YLegend:YUnit:Legend Serie 1;…;Legend Serie n:Serie 1 val 1;…;Serie 1 val m:…:Serie n val 1;…;Serie n val m</pchart>

Stacked bar

<pchart>stackedbar:Title:XLegend:XUnit:YLegend:YUnit:Legend Serie 1;…;Legend Serie n:Serie 1 val 1;…;Serie 1 val m:…:Serie n val 1;…;Serie n val m</pchart>

Limit

<pchart>limit:Title:XLegend:XUnit:YLegend:YUnit:Legend Serie 1;Legend Serie 2:Serie 1 val 1;…;Serie 1 val m:Serie 2 val 1;…;Serie 2 val m</pchart>

Radar

<pchart>radar:Title:Legend Serie 1;…;Legend Serie n:Axis 1 Legend;…;Axis m Legend:Serie 1 val 1;…;Serie 1 val m:…:Serie n val 1;…;Serie n val m</pchart>

Pie

<pchart>pie:Title:Legend 1;…;Legend n:val 1;…;val n</pchart>

Download and Installation

Sorry can't upload file… Need to log?

So, setup :

  • First create the directory /lib/plugins/pchart.
  • Paste the syntax code in a new file /lib/plugins/pchart/syntax.php.
  • Download pChart 1.27 - beta libray here.
  • Unzip it and copy Font and pChart directories (and content) in /lib/plugins/pchart.
  • The plugin is ready to use.

syntax.php

syntax.php
<?php
/**
 * Plugin pChart: Insert pChart graph in your DokuWiki pages.
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Philippe Doussaint <philippe.doussaint [at] freesbee [dot] fr>
 */
 
// must be run within DokuWiki
if(!defined('DOKU_INC')) die();
 
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
// library providing the global 'cleanID()'/'getID()'/'wikiFN()' functions:
require_once(DOKU_INC . 'inc/pageutils.php');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_pchart extends DokuWiki_Syntax_Plugin {
 
    function getInfo(){
 
        return array(
                'author' => 'Philippe Doussaint',
                'email'  => 'philippe.doussaint [at] freesbee [dot] fr',
                'date'   => '2008-08-22',
                'name'   => 'pChart plugin',
                'desc'   => 'Insert pChart graph in your DokuWiki pages.
                            See plugin page for syntax.',
                'url'    => 'http://www.dokuwiki.org/plugin:pChart',
                );
    }
 
    function getType(){ return 'formatting'; }
 
    function getAllowedTypes() { return array('substition'); }   
 
    function getSort() { return 208; }
 
    function connectTo($mode) { $this->Lexer->addEntryPattern('<pchart(?=[^\r\n]*?>.*?</pchart>)',$mode,'plugin_pchart'); }
 
    function postConnect() { $this->Lexer->addExitPattern('</pchart>','plugin_pchart'); } 
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){ 
 
        if ($state == DOKU_LEXER_UNMATCHED ) {
            //keep name (if exist?) and syntax
            list($name, $syntax) = preg_split('/>/u', $match, 2);
            //find align
            if (substr($syntax, 0, 1).substr($syntax, -1) == '  ' ) $align = 'center';
            elseif (substr($syntax, 0, 1) == ' ' ) $align = 'right';
            elseif (substr($syntax, -1) == ' ' ) $align = 'left';
            else $align = 'normal';                   
            //trim syntax
            $syntax=trim($syntax);
            //if name don't exist, we create one, else we removename=...
            if ( $name == "" ) $name = "pchart_".md5($syntax);                
            else $name=preg_replace(array('/name=/'), array(''), $name);
            //and add extension in any case
            $name .= '.png';
            return array($state,array($name, $syntax, $align)); 
        }
        return array();
    }
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) { 
 
        if($mode == 'xhtml'){
 
            $error_level = error_reporting();
            error_reporting($error_level & ~E_NOTICE);
 
            list($state, $match) = $data;
            if ($state ==  DOKU_LEXER_UNMATCHED ) {
                list($name, $syntax, $align) = $match;
                //Just print info for debug
                //$renderer->doc .= $name."-".$syntax."-".$align; 
                // build the chart file
                $this->doChart($name, $syntax);
                // render it             
                $renderer->doc .= $this->getHtmlCode($name, $syntax, $align);
                return true;
            }
            return false;
        }
    }
 
    /**
     * Get HTML code
     */
    function getHtmlCode($name, $syntax, $align) {
 
        $chartNamespace = str_replace(":", "%3A", getNS(getID()));
        $chartWikiFullPath = $chartNamespace.'%3A'.$name;
        //Now, buil html code
        $html_code = '<a href="/lib/exe/detail.php?id='.getID().'&amp;cache=cache&amp;media='.$chartWikiFullPath.'" class="media" title="'.$name.'"><img src="/lib/exe/fetch.php?h=&amp;cache=cache&amp;media='.$chartWikiFullPath.'" class="media';
        switch ($align) {
            case 'left' : $html_code .= 'left" align="left" alt="" /></a>'; break;
            case 'right' : $html_code .= 'right" align="right" alt="" /></a>'; break;
            case 'center' : $html_code .= 'center" alt="" /></a>'; break;
            case 'normal' : $html_code .= '" alt="" /></a>'; break;
        }
        return $html_code;
    }
 
    /**
     * Do chart
     */
    function doChart($name, $syntax) {
 
        global $conf;
 
        $chartFullPath = $conf['mediadir']."/".str_replace(":", "/", getNS(getID())).'/'.$name;
        // Please Fixme ! How can I handle doku cache correctly ?
        //if (!@is_file($chartFullPath)) {
        $data=explode(":",$syntax);
        // switch chart 
        switch ($data[0]) {
            case 'line' : $this->doLine($chartFullPath, $data); break;
            case 'cubic' : $this->doCubic($chartFullPath, $data); break;
            case 'bar' : $this->doBar($chartFullPath, $data); break;
            case 'stackedbar' : $this->doStackedBar($chartFullPath, $data); break;
            case 'limit' : $this->doLimit($chartFullPath, $data); break;
            case 'radar' : $this->doRadar($chartFullPath, $data); break;
 
            case 'pie' : $this->doPie($chartFullPath, $data); break;
 
        //}
        }
        return true;
    }
 
    /* Now that's raw code from examples...
     * Sorry, It's not really clean!!    
     */
 
    /**
     * Do line
     */
    function doLine($chartFullPath, $data) {
 
        // Standard inclusions   
        require_once(DOKU_PLUGIN."pchart/pChart/pData.class");
        require_once(DOKU_PLUGIN."pchart/pChart/pChart.class");
 
        $title = $data[1];
        $xlegend = $data[2];
        $xunit = $data[3];
        $ylegend = $data[4];
        $yunit = $data[5];
        $label = explode(";", $data[6]);
        // Dataset definition      
        $DataSet = new pData;     
        for ($i = 7; $i < count( $data ); $i++){
            $DataSet->AddPoint(explode(";", $data[$i]),"Serie".($i - 6));     
        }
        $DataSet->AddAllSeries();     
        $DataSet->SetAbsciseLabelSerie();     
        for ($i = 7; $i < count( $data ); $i++){
            $DataSet->SetSerieName($label[$i - 7],"Serie".($i - 6));     
        }
        $DataSet->SetXAxisName($xlegend);  
        $DataSet->SetXAxisUnit($xunit);  
        $DataSet->SetYAxisName($ylegend);  
        $DataSet->SetYAxisUnit($yunit);  
 
        // Initialise the graph     
        $Test = new pChart(600,240);     
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",8);     
        $Test->setGraphArea(70,30,500,200);     
        $Test->drawFilledRoundedRectangle(7,7,573,233,5,240,240,240);     
        $Test->drawRoundedRectangle(5,5,575,235,5,230,230,230);     
        $Test->drawGraphArea(255,255,255,TRUE);  
        $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);     
        $Test->drawGrid(4,TRUE,230,230,230,50);  
 
        // Draw the 0 line     
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",8);     
        $Test->drawTreshold(0,143,55,72,TRUE,TRUE);     
 
        // Draw the graph  
        $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());     
        $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);     
 
        // Draw legend
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",10);  
        $Test->drawLegend(510,25,$DataSet->GetDataDescription(),250,250,250);  
 
        // Draw title
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",12);     
        $Test->drawTitle(60,22,$title,0,0,0,-1,8);   
 
        // Render graph
        $Test->Render($chartFullPath);  
 
        return true;
    }
 
    /**
     * Do cubic
     */
    function doCubic($chartFullPath, $data) {
 
        // Standard inclusions   
        require_once(DOKU_PLUGIN."pchart/pChart/pData.class");
        require_once(DOKU_PLUGIN."pchart/pChart/pChart.class");
 
        $title = $data[1];
        $xlegend = $data[2];
        $xunit = $data[3];
        $ylegend = $data[4];
        $yunit = $data[5];
        $label = explode(";", $data[6]);
        // Dataset definition      
        $DataSet = new pData;     
        for ($i = 7; $i < count( $data ); $i++){
            $DataSet->AddPoint(explode(";", $data[$i]),"Serie".($i - 6));     
        }
        $DataSet->AddAllSeries();     
        $DataSet->SetAbsciseLabelSerie();     
        for ($i = 7; $i < count( $data ); $i++){
            $DataSet->SetSerieName($label[$i - 7],"Serie".($i - 6));     
        }
        $DataSet->SetXAxisName($xlegend);  
        $DataSet->SetXAxisUnit($xunit);  
        $DataSet->SetYAxisName($ylegend);  
        $DataSet->SetYAxisUnit($yunit);  
 
        // Initialise the graph     
        $Test = new pChart(600,240);     
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",8);     
        $Test->setGraphArea(70,30,500,200);     
        $Test->drawFilledRoundedRectangle(7,7,573,233,5,240,240,240);     
        $Test->drawRoundedRectangle(5,5,575,235,5,230,230,230);     
        $Test->drawGraphArea(255,255,255,TRUE);  
        $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);     
        $Test->drawGrid(4,TRUE,230,230,230,50);  
 
        // Draw the 0 line     
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",8);     
        $Test->drawTreshold(0,143,55,72,TRUE,TRUE);     
 
        // Draw the graph  
        $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());  
 
        // Draw legend
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",10);  
        $Test->drawLegend(510,25,$DataSet->GetDataDescription(),250,250,250);  
 
        // Draw title
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",12);     
        $Test->drawTitle(60,22,$title,0,0,0,-1,8);   
 
        // Render graph
        $Test->Render($chartFullPath);  
 
        return true;
    }
 
    /**
     * Do bar
     */
    function doBar($chartFullPath, $data) {
 
        // Standard inclusions   
        require_once(DOKU_PLUGIN."pchart/pChart/pData.class");
        require_once(DOKU_PLUGIN."pchart/pChart/pChart.class");
 
        $title = $data[1];
        $xlegend = $data[2];
        $xunit = $data[3];
        $ylegend = $data[4];
        $yunit = $data[5];
        $label = explode(";", $data[6]);
        // Dataset definition      
        $DataSet = new pData;     
        for ($i = 7; $i < count( $data ); $i++){
            $DataSet->AddPoint(explode(";", $data[$i]),"Serie".($i - 6));     
        }
        $DataSet->AddAllSeries();     
        $DataSet->SetAbsciseLabelSerie();     
        for ($i = 7; $i < count( $data ); $i++){
            $DataSet->SetSerieName($label[$i - 7],"Serie".($i - 6));     
        }
        $DataSet->SetXAxisName($xlegend);  
        $DataSet->SetXAxisUnit($xunit);  
        $DataSet->SetYAxisName($ylegend);  
        $DataSet->SetYAxisUnit($yunit);  
 
        // Initialise the graph     
        $Test = new pChart(600,240);     
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",8);     
        $Test->setGraphArea(70,30,500,200);     
        $Test->drawFilledRoundedRectangle(7,7,573,233,5,240,240,240);     
        $Test->drawRoundedRectangle(5,5,575,235,5,230,230,230);     
        $Test->drawGraphArea(255,255,255,TRUE);  
        $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE);     
        $Test->drawGrid(4,TRUE,230,230,230,50);  
 
        // Draw the 0 line     
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",8);     
        $Test->drawTreshold(0,143,55,72,TRUE,TRUE);     
 
        // Draw the graph  
        $Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE); 
 
        // Draw legend
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",10);  
        $Test->drawLegend(510,25,$DataSet->GetDataDescription(),250,250,250);  
 
        // Draw title
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",12);     
        $Test->drawTitle(60,22,$title,0,0,0,-1,8);   
 
        // Render graph
        $Test->Render($chartFullPath);  
 
        return true;
    }
 
    /**
     * Do stacked bar
     */
    function doStackedBar($chartFullPath, $data) {
 
        // Standard inclusions   
        require_once(DOKU_PLUGIN."pchart/pChart/pData.class");
        require_once(DOKU_PLUGIN."pchart/pChart/pChart.class");
 
        $title = $data[1];
        $xlegend = $data[2];
        $xunit = $data[3];
        $ylegend = $data[4];
        $yunit = $data[5];
        $label = explode(";", $data[6]);
        // Dataset definition      
        $DataSet = new pData;     
        for ($i = 7; $i < count( $data ); $i++){
            $DataSet->AddPoint(explode(";", $data[$i]),"Serie".($i - 6));     
        }
        $DataSet->AddAllSeries();
        $DataSet->SetAbsciseLabelSerie();     
        for ($i = 7; $i < count( $data ); $i++){
            $DataSet->SetSerieName($label[$i - 7],"Serie".($i - 6));     
        }
        $DataSet->SetXAxisName($xlegend);  
        $DataSet->SetXAxisUnit($xunit);  
        $DataSet->SetYAxisName($ylegend);  
        $DataSet->SetYAxisUnit($yunit);  
 
        // Initialise the graph     
        $Test = new pChart(600,240);     
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",8);     
        $Test->setGraphArea(70,30,500,200);     
        $Test->drawFilledRoundedRectangle(7,7,573,233,5,240,240,240);     
        $Test->drawRoundedRectangle(5,5,575,235,5,230,230,230);     
        $Test->drawGraphArea(255,255,255,TRUE);  
        $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_ADDALL,150,150,150,TRUE,0,0,TRUE);     
        $Test->drawGrid(4,TRUE,230,230,230,50);  
 
        // Draw the 0 line     
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",8); 
        $Test->drawTreshold(0,143,55,72,TRUE,TRUE);     
 
        // Draw the graph  
        $Test->drawStackedBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
        // Draw legend
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",10);  
        $Test->drawLegend(510,25,$DataSet->GetDataDescription(),250,250,250);
 
        // Draw title
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",12);   
        $Test->drawTitle(60,22,$title,0,0,0,-1,8);   
 
        // Render graph
        $Test->Render($chartFullPath);  
 
        return true;
    }
 
    /**
     * Do limit
     */
    function doLimit($chartFullPath, $data) {
 
        // Standard inclusions   
        require_once(DOKU_PLUGIN."pchart/pChart/pData.class");
        require_once(DOKU_PLUGIN."pchart/pChart/pChart.class");
 
        $title = $data[1];
        $xlegend = $data[2];
        $xunit = $data[3];
        $ylegend = $data[4];
        $yunit = $data[5];
        $label = explode(";", $data[6]);
        $serie1 = explode(";", $data[7]);
        $serie2 = explode(";", $data[8]);
 
        // Dataset definition      
        $DataSet = new pData;     
        $DataSet->AddPoint($serie1,"Serie1");  
        $DataSet->AddPoint($serie2,"Serie2");  
        $DataSet->AddAllSeries();  
        $DataSet->SetAbsciseLabelSerie();  
        $DataSet->SetSerieName($label[0],"Serie1");  
        $DataSet->SetSerieName($label[1],"Serie2");  
        $DataSet->SetXAxisName($xlegend);  
        $DataSet->SetXAxisUnit($xunit);  
        $DataSet->SetYAxisName($ylegend);  
        $DataSet->SetYAxisUnit($yunit);  
 
        // Initialise the graph     
        $Test = new pChart(600,240);     
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",8);     
        $Test->setGraphArea(70,30,500,200);     
        $Test->drawFilledRoundedRectangle(7,7,573,233,5,240,240,240);     
        $Test->drawRoundedRectangle(5,5,575,235,5,230,230,230);     
        $Test->drawGraphArea(255,255,255,TRUE);  
        $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_ADDALL,150,150,150,TRUE,0,0,TRUE);     
        $Test->drawGrid(4,TRUE,230,230,230,50);  
 
        // Draw the 0 line     
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",8); 
        $Test->drawTreshold(0,143,55,72,TRUE,TRUE);     
 
        // Draw the graph  
        $Test->drawLimitsGraph($DataSet->GetData(),$DataSet->GetDataDescription(),180,180,180); 
 
        // Draw legend
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",10);  
        $Test->drawLegend(510,25,$DataSet->GetDataDescription(),250,250,250);
 
        // Draw title
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",12);   
        $Test->drawTitle(60,22,$title,0,0,0,-1,8);   
 
        // Render graph
        $Test->Render($chartFullPath);  
 
        return true;
    }
 
    /**
     * Do radar bar
     */
    function doRadar($chartFullPath, $data) {
 
        // Standard inclusions   
        require_once(DOKU_PLUGIN."pchart/pChart/pData.class");
        require_once(DOKU_PLUGIN."pchart/pChart/pChart.class");
 
        $title = $data[1];
        $label = explode(";", $data[2]);
        // Dataset definition      
        $DataSet = new pData; 
        $DataSet->AddPoint(explode(";", $data[3]),"Label");    
        for ($i = 4; $i < count( $data ); $i++){
            $DataSet->AddPoint(explode(";", $data[$i]),"Serie".($i - 3));
            $DataSet->AddSerie("Serie".($i - 3));  
        }
 
        $DataSet->SetAbsciseLabelSerie("Label");          
        for ($i = 0; $i < count( $label ); $i++){
            $DataSet->SetSerieName($label[$i],"Serie".($i+1));     
        }
 
        // Initialise the graph  
        $Test = new pChart(300,240);  
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",8);  
        $Test->drawFilledRoundedRectangle(7,7,273,233,5,240,240,240);  
        $Test->drawRoundedRectangle(5,5,275,235,5,230,230,230);  
        $Test->setGraphArea(35,30,185,220);  
 
        // Draw the graph  
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",8);  
        $Test->drawRadarAxis($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE,20,120,120,120,230,230,230);  
        $Test->drawFilledRadar($DataSet->GetData(),$DataSet->GetDataDescription(),20,20);  
 
        // Draw legend
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",10);  
        $Test->drawLegend(210,25,$DataSet->GetDataDescription(),255,255,255);  
 
        // Draw title
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",12);  
        $Test->drawTitle(60,22,$title,0,0,0,-1,8);   
 
        // Render graph
        $Test->Render($chartFullPath);  
 
        return true;
    }
 
 
    /**
     * Do pie
     */
    function doPie($chartFullPath, $data) {
 
        $title=$data[1];
        $serie1=explode(";",$data[3]);
        $serie2=explode(";",$data[2]);
 
        // Standard inclusions   
        require_once(DOKU_PLUGIN."pchart/pChart/pData.class");
        require_once(DOKU_PLUGIN."pchart/pChart/pChart.class");
 
        // Dataset definition   
        $DataSet = new pData; 
        $DataSet->AddPoint($serie1,"Serie1");  
        $DataSet->AddPoint($serie2,"Serie2");  
        $DataSet->AddAllSeries();  
        $DataSet->SetAbsciseLabelSerie("Serie2");  
 
        // Init the graph  
        $Test = new pChart(300, 240);  
        $Test->drawFilledRoundedRectangle(7,7,273,237,5,240,240,240);  
        $Test->drawRoundedRectangle(5,5,275,235,5,230,230,230);  
 
        // Draw legend
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",10);  
        $Test->drawPieLegend(210,25,$DataSet->GetData(), $DataSet->GetDataDescription(),250,250,250);  
 
        // Draw the graph  
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",8);  
        $Test->drawPieGraph($DataSet->GetData(),$DataSet->GetDataDescription(),115,130,70,PIE_PERCENTAGE,TRUE,90,20,10);  
 
        // Draw title
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",12);     
        $Test->drawTitle(60,22,$title,0,0,0,-1,8);   
 
        // Render graph
        $Test->Render($chartFullPath);  
 
        return true;
    }
 
}

Bugs

2008-09-05

function getHtmlCode doesn't return the good URL when DokuWiki isn't in the root web dir…

  • change the function getHtmlCode from
    //Now, buil html code
    $html_code = '<a href="/lib/exe/detail.php?id='.getID().'&amp;cache=cache&amp;media='.$chartWikiFullPath.'" class="media" title="'.$name.'"><img src="/lib/exe/fetch.php?h=&amp;cache=cache&amp;media='.$chartWikiFullPath.'" class="media';

    to

    $fetchpath = DOKU_URL."/lib/exe/fetch.php";
    $detailpath = DOKU_URL."/lib/exe/detail.php";
    //Now, build html code
    $html_code = '<a href="'.$detailpath.'?id='.getID().'&amp;cache=cache&amp;media='.$chartWikiFullPath.'" class="media" title="'.$name.'"><img src="'.$fetchpath.'?h=&amp;cache=cache&amp;media='.$chartWikiFullPath.'" class="media';

    Here is a unified diff

    --- syntax.orig.php     2008-09-09 16:36:15.046875000 +0200
    +++ syntax.php  2008-09-09 16:37:58.765625000 +0200
    @@ -101,8 +101,10 @@
     
             $chartNamespace = str_replace(":", "%3A", getNS(getID()));
             $chartWikiFullPath = $chartNamespace.'%3A'.$name;
    +        $fetchpath = DOKU_URL."/lib/exe/fetch.php";
    +        $detailpath = DOKU_URL."/lib/exe/detail.php";
             //Now, buil html code
    -        $html_code = '<a href="/lib/exe/detail.php?id='.getID().'&amp;cache=cache&amp;media='.$chartWikiFullPath.'" class="media" title="'.$name.'"><img src="/lib/exe/fetch.php?h=&amp;cache=cache&amp;media='.$chartWikiFullPath.'" class="media';
    +        $html_code = '<a href="'.$detailpath.'?id='.getID().'&amp;cache=cache&amp;media='.$chartWikiFullPath.'" class="media" title="'.$name.'"><img src="'.$fetchpath.'?h=&amp;cache=cache&amp;media='.$chartWikiFullPath.'" class="media';
             switch ($align) {
                 case 'left' : $html_code .= 'left" align="left" alt="" /></a>'; break;
                 case 'right' : $html_code .= 'right" align="right" alt="" /></a>'; break;


    Uwe Kirbach – 09.09.2008

Thanks a lot, Uwe! I find nearly the same issue, Philippe Doussaint

2008-09-10

The plugin can't create the namespace dir in media dir, if it doesn't exist… So the render crashes.

Is there a way to do it with a DokuWiki function? Philippe Doussaint

  • change the function doChart from
    $chartFullPath = $conf['mediadir']."/".str_replace(":", "/", getNS(getID())).'/'.$name;

    to

    $chartFullPath = $conf['mediadir']."/".str_replace(":", "/", getNS(getID()));
    if (!is_dir($chartFullPath)) mkdir($chartFullPath,$conf['dmode']);
    $chartFullPath = $chartFullPath.'/'.$name;

    Domingo RedalDomingo Redal
    docXML

    – 2010.10.31

Feedback - Discussion

Do you use it?

Is it what you need?

Is the syntax ugly?

Yes, I find it's ugly… For the next release would like to use a “global syntax” : Perhaps, somethings like :

chart_type:title:labels:axis_legends:axis_units:values1:values2:...

Do you have more ideas?

Why not make it multi-line?
  <pchart>
  type=chart_type
  title=title
  serie
  {
    label=
    values=1.00,2.00,3.55
  }
  serie
  {
    label=
    values=3,4,5
  }
  </pchart>
This way arguments can be omitted, series name and values can be seen closer together, and using comma instead of ';' is closer to //Google Chart// syntax.

Do you want to use it to plot math function?

Acronyms bug

Having a pchart with a defined acronym inside the syntax bug. Example: <pchart> cubic:HTML chart:…. </pchart>

Seem to be fixed by replacing in syntax.php FROM

    function getAllowedTypes() { return array('substition'); }

TO

    function getAllowedTypes() { return array('disabled'); }

Bug in name

Fix the named chart bug: Replace in syntax.php

            //if name don't exist, we create one, else we removename=...
            if ( $name == "" ) $name = "pchart_".md5($syntax);
            else $name=preg_replace(array('/name=/'), array(''), $name);
            //and add extension in any case

by

            //if name don't exist, we create one, else we removename=...
            if (preg_match('/name=([A-Za-z0-9.:_-]+)/', $name, $matches))
                $name = $matches[1];
            else
                $name = "pchart_".md5($syntax);  ;
            //and add extension in any case

Anymore else?

Add option to set X-scale values in Bar chart

by Oded Gabbay (ogabbay@advaoptical.com)

The syntax for bar chart will be:

<pchart>bar:Title:XLegend:XUnit:X SCale val 1;…;X Scale val m:YLegend:YUnit:Legend Serie 1;…;Legend Serie n:Serie 1 val 1;…;Serie 1 val m:…:Serie n val 1;…;Serie n val m</pchart>

Change function doBar in syntax.php to:

    function doBar($chartFullPath, $data) {
 
        // Standard inclusions   
        require_once(DOKU_PLUGIN."pchart/pChart/pData.class");
        require_once(DOKU_PLUGIN."pchart/pChart/pChart.class");
 
        $title = $data[1];
        $xlegend = $data[2];
        $xunit = $data[3];
        $ylegend = $data[5];
        $yunit = $data[6];
        $label = explode(";", $data[7]);
        // Dataset definition      
        $DataSet = new pData;     
        for ($i = 8; $i < count( $data ); $i++){
            $DataSet->AddPoint(explode(";", $data[$i]),"Serie".($i - 7));     
        }
        $DataSet->AddAllSeries();     
        $DataSet->AddPoint(explode(";", $data[4]),"Label");           
        $DataSet->SetAbsciseLabelSerie("Label");     
        for ($i = 8; $i < count( $data ); $i++){
            $DataSet->SetSerieName($label[$i - 8],"Serie".($i - 7));     
        }
        $DataSet->SetXAxisName($xlegend);  
        $DataSet->SetXAxisUnit($xunit);  
        $DataSet->SetYAxisName($ylegend);  
        $DataSet->SetYAxisUnit($yunit);  
 
        // Initialise the graph     
        $Test = new pChart(600,240);     
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",8);     
        $Test->setGraphArea(70,30,500,200);     
        $Test->drawFilledRoundedRectangle(7,7,573,233,5,240,240,240);     
        $Test->drawRoundedRectangle(5,5,575,235,5,230,230,230);     
        $Test->drawGraphArea(255,255,255,TRUE);  
        $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE);     
        $Test->drawGrid(4,TRUE,230,230,230,50);  
 
        // Draw the 0 line     
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",8);     
        $Test->drawTreshold(0,143,55,72,TRUE,TRUE);     
 
        // Draw the graph  
        $Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE); 
 
        // Draw legend
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",10);  
        $Test->drawLegend(510,25,$DataSet->GetDataDescription(),250,250,250);  
 
        // Draw title
        $Test->setFontProperties(DOKU_PLUGIN."pchart/Fonts/tahoma.ttf",12);     
        $Test->drawTitle(60,22,$title,0,0,0,-1,8);   
 
        // Render graph
        $Test->Render($chartFullPath);  
 
        return true;
    }
plugin/pchart.txt · Last modified: 2014-10-12 15:59 by Aleksandr