View unanswered posts | View active topics It is currently Wed May 08, 2024 10:53 am



Reply to topic  [ 1 post ] 
Using pChart on Moodle 
Author Message
New pChart user
New pChart user

Joined: Fri Oct 21, 2011 7:03 pm
Posts: 1
 Using pChart on Moodle
Hi, I'm trying to use pChart Library on a Module for Moodle (development in php). I have in Moodle the next source code to show a graphic:

Code:
$imagepathurl = $CFG->wwwroot.'/mod/khronos/';
$element = $mform->getElement($this->_nameform.'graphic');
$element->setValue('<div class="mdl-align"><img src="'.$imagepathurl.'linegraph.php" alt="'.get_string('infographic', 'khronos').'" /></div>');


I call to the script php linegraph.php, and the result is a graphic. But I want to customize the values of the axis, for example, "Serie 1", "Serie 2", etc. With an array that I generate before the call.

The code of the graphic:

Code:
<?php
require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); //Includes

global $CFG, $USER;

/* pChart library inclusions */
include($CFG->dirroot.'/mod/khronos/class/pData.class.php');
include($CFG->dirroot.'/mod/khronos/class/pDraw.class.php');
include($CFG->dirroot.'/mod/khronos/class/pImage.class.php');
$myData = new pData();

$myData->addPoints(array(6,0,0,4,2,1,0,0),"Serie1");
$myData->setSerieDescription("Serie1","Serie 1");
$myData->setSerieOnAxis("Serie1",0);

$myData->addPoints(array(0,2,2,1,0,1,1,4),"Serie2");
$myData->setSerieDescription("Serie2","Serie 2");
$myData->setSerieOnAxis("Serie2",0);

$myData->addPoints(array(0,0,0,5,0,4,1,0),"Serie3");
$myData->setSerieDescription("Serie3","Serie 3");
$myData->setSerieOnAxis("Serie3",0);

$myData->addPoints(array("January","","","April","","","July",""),"Absissa");
$myData->setAbscissa("Absissa");

$myData->setAxisPosition(0,AXIS_POSITION_LEFT);
$myData->setAxisName(0,"1st axis");
$myData->setAxisUnit(0,"");

$myPicture = new pImage(700,230,$myData,TRUE);
$myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));

$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>50,"G"=>50,"B"=>50,"Alpha"=>20));

$myPicture->setShadow(FALSE);
$myPicture->setGraphArea(50,50,675,190);
$myPicture->setFontProperties(array("R"=>0,"G"=>0,"B"=>0,"FontName"=>"fonts/pf_arma_five.ttf","FontSize"=>6));

$Settings = array("Pos"=>SCALE_POS_LEFTRIGHT
, "Mode"=>SCALE_MODE_FLOATING
, "LabelingMethod"=>LABELING_ALL
, "GridR"=>255, "GridG"=>255, "GridB"=>255, "GridAlpha"=>50, "TickR"=>0, "TickG"=>0, "TickB"=>0, "TickAlpha"=>50, "LabelRotation"=>0, "CycleBackground"=>1, "DrawXLines"=>1, "DrawSubTicks"=>1, "SubTickR"=>255, "SubTickG"=>0, "SubTickB"=>0, "SubTickAlpha"=>50, "DrawYLines"=>ALL);
$myPicture->drawScale($Settings);

$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>50,"G"=>50,"B"=>50,"Alpha"=>10));

$Config = array("DisplayValues"=>1);
$myPicture->drawLineChart($Config);

$Config = array("FontR"=>0, "FontG"=>0, "FontB"=>0, "FontName"=>"fonts/pf_arma_five.ttf", "FontSize"=>6, "Margin"=>6, "Alpha"=>30, "BoxSize"=>5, "Style"=>LEGEND_NOBORDER
, "Mode"=>LEGEND_HORIZONTAL
);
$myPicture->drawLegend(563,16,$Config);

$myPicture->stroke();
?>


I want to change the next:

Code:
$myData->addPoints(array(6,0,0,4,2,1,0,0),"Serie1");
$myData->setSerieDescription("Serie1","Serie 1");
$myData->setSerieOnAxis("Serie1",0);


By:

Code:
$myData->addPoints($graphData,"Serie1");
$myData->setSerieDescription("Serie1","Serie 1");
$myData->setSerieOnAxis("Serie1",0);


But do not know how I can send this array to the file, to customize the data.

Can you give me some help? Thank you very much. :cry:


Fri Oct 21, 2011 7:14 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron