Artichow : Forum Artichow !
Ajout Seuil, moyenne, tendance linéaire dans artichow
Auteur: peofofo (IP enregistrée)
Date: le 27 décembre 2009, 10:04

Bonjour,

J'ai ajouté les courbes de seuil, moyenne, tendance linéaire, dans artichow

voici un exemple:



Voici le code de l'exemple:

require_once "../LinePlot.class.php";
$graph = new Graph(400, 300);
$graph->setAntiAliasing(TRUE);

$x = array(
45, 67, 23, 45, 62, 10, 25
);

$plot = new LinePlot($x);

$plot->setSpace(6, 6, 10, 10);
$plot->setXAxisZero(FALSE);

// Set a background gradient
$plot->setBackgroundGradient(
new LinearGradient(
new Color(210, 210, 210),
new Color(255, 255, 255),
0
)
);

// Change line color
$plot->setColor(new Color(0, 0, 150, 20));

// Set line background gradient
$plot->setFillGradient(
new LinearGradient(
new Color(150, 150, 210),
new Color(230, 230, 255),
90
)
);

// Change mark type
$plot->mark->setType(Mark::CIRCLE);
$plot->mark->border->show();

// Ajout de Moyenne
$moy= new LinePlot($x,'', awLinePlot::MOYENNE);
$moy->setColor(new Color(255, 0, 0, 20));

// Ajout de Seuil max
$seuil_max= new LinePlot($x,'', awLinePlot::SEUIL);
$seuil_max->setSeuil(60);
$seuil_max->setColor(new Color(55, 155, 55, 20));

// Ajout de Seuil min
$seuil_min= new LinePlot($x,'', awLinePlot::SEUIL);
$seuil_min->setSeuil(20);
$seuil_min->setColor(new Color(55, 155, 55, 20));

//Tendance
$tendance= new LinePlot($x,'', awLinePlot::TENDANCE);
$tendance->setColor(new Color(0, 255, 0, 20));

$group = new PlotGroup;
$group->add($plot);
$group->add($moy);
$group->add($seuil_max);
$group->add($seuil_min);
$group->add($tendance);
$group->legend->add($plot, "Courbe", Legend::LINE);
$group->legend->add($moy, "Moyenne", Legend::LINE);
$group->legend->add($tendance, "Tendance", Legend::LINE);
$group->legend->add($seuil_max, "Seuil Max", Legend::LINE);
$group->legend->add($seuil_min, "Seuil Min", Legend::LINE);
$group->legend->setSpace(6);
$group->legend->setPosition(0.94, 0.23);
$graph->add($group);
$graph->draw();
?>

Si des personnes sont intéressés pour obtenir les classes d'artichow.



Message édité 1 fois. Dernière modification le le 27/12/09 à 10:44

Re: Ajout Seuil, moyenne, tendance linéaire dans artichow
Auteur: emytom (IP enregistrée)
Date: le 18 juin 2010, 19:16

Bonjour , suite a un projet je serais très intéressé d'obtenir les classes ajout de seuils , cela m'aidera beaucoup

Re: Ajout Seuil, moyenne, tendance linéaire dans artichow
Auteur: carter (IP enregistrée)
Date: le 24 juin 2010, 18:54

Bonjour,

Je serais particulièrement intéressé par la courbe de tendance, et je pense que les autres pourraient aussi me servir.

J'aimerais donc pouvoir profiter de tes modifications.


Merci.



Re: Ajout Seuil, moyenne, tendance linéaire dans artichow
Auteur: peofofo (IP enregistrée)
Date: le 29 juin 2010, 19:44

Bonjour,

Il te faut ajouter dans le fichier LinePlot.class

protected $lineType = awLinePlot::POLYGONE;
//les constantes:
const POLYGONE = 0;
const SEUIL = 1;
const MOYENNE = 2;
const TENDANCE = 3;

//J'ajoute le type au constructeur:
public function __construct($values, $mode = awLinePlot::LINE, $type = awLinePlot::POLYGONE) {
//Je lui défini son attribut:
$this->lineType = (int)$type;
} //Fermeture du constructeur

//Modifier la fonction drawComponent

public function drawComponent(awDriver $driver, $x1, $y1, $x2, $y2, $aliasing) {

$max = $this->getRealYMax();
$min = $this->getRealYMin();

// Get start and stop values
list($start, $stop) = $this->getLimit();

if($this->lineMode === awLinePlot::MIDDLE) {
$inc = $this->xAxis->getDistance(0, 1) / 2;
} else {
$inc = 0;
}

// Build the polygon
$polygon = new awPolygon;
if($this->lineType==0) {// Polygone courbe
for($key = $start; $key <= $stop; $key++) {

$value = $this->datay[$key];

if($value !== NULL) {

$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $value));
$p = $p->move($inc, 0);
$polygon->set($key, $p);

}

}
}
elseif($this->lineType==1) {// Seuil --> Droite
if(isset($this->seuil)) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(0, $this->seuil));
$p = $p->move($inc, 0);
$polygon->set(0, $p);
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(count($this->datay)-1, $this->seuil));
$p = $p->move($inc, 0);
$polygon->set(count($this->datay)-1, $p);
}
}
elseif($this->lineType==2) {// Moyenne --> Droite
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(0, round(array_sum($this->datay)/count($this->datay), 2)));
$p = $p->move($inc, 0);
$polygon->set(0, $p);
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(count($this->datay)-1, round(array_sum($this->datay)/count($this->datay), 2)));
$p = $p->move($inc, 0);
$polygon->set(count($this->datay)-1, $p);
}
elseif($this->lineType==3) {//Tendance --> Droite
//Calcul de la tendance lineaire
$x=0;
// On calcul x barre
for($i=1;$i<count($this->datay)+1;$i++){
$x+=$i;
}
$x_=$x/count($this->datay);
$y_=array_sum($this->datay)/count($this->datay);
// On calcul x²
$xx=0;
for($i=1;$i<count($this->datay)+1;$i++){
$xx+=pow($i,2);
}
$sxx=$xx/count($this->datay)-(pow($x_,2));
// On calcul xy produit
$xy=0;
for($i=1;$i<count($this->datay)+1;$i++){
$xy+=$i*$this->datay[$i-1];
}
$sxy=$xy/count($this->datay)-($x_*$y_);
$a=$sxy/$sxx;
$b=$y_-($a*$x_);
$c=$a*(count($this->datay)-1)+$b;
// Coube lineaire ax+b -->$ax+$b
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(0, $a+$b));// point 1 --> x=1
$p = $p->move($inc, 0);
$polygon->set(0, $p);
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(count($this->datay)-1, $a*(count($this->datay))+$b));// point 2
$p = $p->move($inc, 0);
$polygon->set(count($this->datay)-1, $p);
}

Il faut modifier le fichier Plot.class.php

Il faut ajouté dans 'abstract class awPlot extends awComponent' :

protected $seuil;


Après la fonction 'setXMax' il faut ajouter la fonction :
public function setSeuil($seuil) {
$this->seuil = $seuil;

}

Le code a implémenter dans la page se trouve au poste du dessus.

Salutations,




Message édité 3 fois. Dernière modification le le 07/07/10 à 00:24

Re: Ajout Seuil, moyenne, tendance linéaire dans artichow
Auteur: cjordi (IP enregistrée)
Date: le 6 juillet 2010, 10:40

Bonjour,


C'est exactement ce qu'il me faut pour mon projet !!

Je suis nouvel utilisateur d'Artichow, novice en création de graphique et j'ai un problème :

Quand je rajoute dans le fichier LinePlot.class :

"protected $lineType = awLinePlot::POLYGONE;
//les constantes:
[...]
$polygon->set(count($this->datay)-1, $p);
}
"
J'ai une erreur qui s'affiche lorsque je veux afficher mon graph :

"Parse error: syntax error, unexpected T_PROTECTED in W:\var\www\fingerprint\graph\php5\LinePlot.class.php on line 590"

La ligne 590 correspond à : "protected $lineType = awLinePlot::POLYGONE;"

Ai-je mis ton code au bon endroit ? artichow\php5\LinePlot.class.php

Merci par avance.


Re: Ajout Seuil, moyenne, tendance linéaire dans artichow
Auteur: cjordi (IP enregistrée)
Date: le 6 juillet 2010, 15:10

Désolé pour le message précédent, j'ai fais le boulet. Je n'ai pas lu correctement comment modifier le LinePlot.class.php

Cette fois ci je l'ai fais avec rigueur ^^.

Mais j'ai tout de même encore un problème lol.

J'ai des erreurs pour ces 2 lignes :

Fatal error: Call to undefined method LinePlot::setSeuil() in W:\var\www\fingerprint\graph\examples\tutorials\newtest.php on line 48

48 : $seuil_max->setSeuil(60);

Fatal error: Call to undefined method LinePlot::setSeuil() in W:\var\www\fingerprint\graph\examples\tutorials\newtest.php on line 53

53 : $seuil_min->setSeuil(20);

Je n'ai fais que recopier bêtement le code ci dessus.
Avez vous une idée ? Merci d'avance?



Re: Ajout Seuil, moyenne, tendance linéaire dans artichow
Auteur: peofofo (IP enregistrée)
Date: le 6 juillet 2010, 23:26

Bonsoir,

Effectivement, j'ai oublié de mettre la fonction de setSeuil()


Il faut modifier le fichier Plot.class.php

Il faut ajouté dans 'abstract class awPlot extends awComponent' :

protected $seuil;


Après la fonction 'setXMax' il faut ajouter la fonction :
public function setSeuil($seuil) {
$this->seuil = $seuil;

}

Normalement, ça devrait marcher.

Salutations

Edit: fonctionne également avec la courbe d'un histogramme:

Par contre les courbes s'arrêtent sur le trait du point.
//Il faut ajouter : LinePlot::MIDDLE
$moy= new LinePlot($x, LinePlot::MIDDLE, awLinePlot::MOYENNE);

Je n'avais pas corrigé la classe ci dessus!
Il faut rajouter avant chaques "$polygon->set":
$p = $p->move($inc, 0);

Correction:
if($this->lineType==0) {// Polygone courbe
for($key = $start; $key <= $stop; $key++) {

$value = $this->datay[$key];

if($value !== NULL) {

$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $value));
$p = $p->move($inc, 0);
$polygon->set($key, $p);

}

}
}
elseif($this->lineType==1) {// Seuil --> Droite
if(isset($this->seuil)) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(0, $this->seuil));
$p = $p->move($inc, 0);
$polygon->set(0, $p);
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(count($this->datay)-1, $this->seuil));
$p = $p->move($inc, 0);
$polygon->set(count($this->datay)-1, $p);
}
}
elseif($this->lineType==2) {// Moyenne --> Droite
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(0, round(array_sum($this->datay)/count($this->datay), 2)));
$p = $p->move($inc, 0);
$polygon->set(0, $p);
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(count($this->datay)-1, round(array_sum($this->datay)/count($this->datay), 2)));
$p = $p->move($inc, 0);
$polygon->set(count($this->datay)-1, $p);
}
elseif($this->lineType==3) {//Tendance --> Droite
//Calcul de la tendance lineaire
$x=0;
// On calcul x barre
for($i=1;$i<count($this->datay)+1;$i++){
$x+=$i;
}
$x_=$x/count($this->datay);
$y_=array_sum($this->datay)/count($this->datay);
// On calcul x²
$xx=0;
for($i=1;$i<count($this->datay)+1;$i++){
$xx+=pow($i,2);
}
$sxx=$xx/count($this->datay)-(pow($x_,2));
// On calcul xy produit
$xy=0;
for($i=1;$i<count($this->datay)+1;$i++){
$xy+=$i*$this->datay[$i-1];
}
$sxy=$xy/count($this->datay)-($x_*$y_);
$a=$sxy/$sxx;
$b=$y_-($a*$x_);
$c=$a*(count($this->datay)-1)+$b;
// Coube lineaire ax+b -->$ax+$b
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(0, $a+$b));// point 1 --> x=1
$p = $p->move($inc, 0);
$polygon->set(0, $p);
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(count($this->datay)-1, $a*(count($this->datay))+$b));// point 2
$p = $p->move($inc, 0);
$polygon->set(count($this->datay)-1, $p);
}


J'ai mis a jour le post au dessus.



Message édité 4 fois. Dernière modification le le 07/07/10 à 00:25

Re: Ajout Seuil, moyenne, tendance linéaire dans artichow
Auteur: cjordi (IP enregistrée)
Date: le 7 juillet 2010, 11:51

Bonjour,

Effectivement ça va mieux :) merci pour votre aide.

Maintenant le graphe s'affiche bien mais sans les courbes. la légende y est. Enfaite j'ai un graphique vide.

J'ai bien suivis votre procédure et pris votre code tout bêtement pour tester si tout va bien, avant de mettre ma propre courbe et personnaliser le graphe.

Me cachez-vous encore des choses :p ? Sinon est-ce possible de récupérer vos fichiers "LinePlot.class" et "Plot.class" ?

Je vous remercie.

Cordialement.

Re: Ajout Seuil, moyenne, tendance linéaire dans artichow
Auteur: peofofo (IP enregistrée)
Date: le 7 juillet 2010, 20:03

Est il possible de voir le code de vos pages?

Il est possible que j'ai oublié encore une modif, comme ça fait déjà longtemps que j'ai faite la modification.

Mais normalement, ce que je vous est mis devrait fonctionner! Relisez, et vérifiez que vous n'avez pas oublié de déclaré d'attribut!
Vous n'aurez pas oublié de mettre cette ligne dans le constructeur : "$this->lineType = (int)$type; "

A mon avis, il y a surement une erreur dans votre page.





Message édité 1 fois. Dernière modification le le 07/07/10 à 20:06

Re: Ajout Seuil, moyenne, tendance linéaire dans artichow
Auteur: cjordi (IP enregistrée)
Date: le 18 juillet 2010, 23:42

Bonjour,

Désolé pour le temps de réponse !! J'étais en vacances.

En effet j'ai bien recommencé, étape par étape et votre code fonctionne à merveille.

Je vous remercie pour cela et pour votre assistance !

Cordialement,
Jordi.



Seules les personnes enregistrées peuvent poster sur ce forum.