Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > Images > JpGraph
JpGraph Forum d'entraide pour la bibliothèque JpGraph permettant de manipuler des images en PHP. Avant de poster -> tutoriels JpGraph
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 13/07/2011, 14h32   #1
Invité de passage
 
Homme
Administrateur de base de données
Inscription : mars 2011
Messages : 21
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : Suisse

Informations professionnelles :
Activité : Administrateur de base de données
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : mars 2011
Messages : 21
Points : 0
Points : 0
Par défaut Souci avec Radar Plot

Bonjour,

Je voudrais générer un radar avec les valeurs récupérée dans ma base données

Voici ce que pourrais se trouver dans un array :

Code :
1
2
3
$x=array(10,20,50,15,30,25,30,40,50,15)
$y= array('A','B','C','D','E');
$xy = array('Exemple'=>array(10,20,50,15,30),'Objectif'=>array(25,30,40,50,15));

voici mon code qui ne marche pas ;

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 
 
<?php // content="text/plain; charset=utf-8"
// 8 : RADAR  
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_radar.php');
 
 
$x=array(10,20,50,15,30,25,30,40,50,15)
$y= array('A','B','C','D','E');
$xy = array('Exemple'=>array(10,20,50,15,30),'Objectif'=>array(25,30,40,50,15));
 
$graph = new RadarGraph($width,$height);
$graph->SetFrame(false);
 
 
$graph->SetScale('lin',0,max($x));
$graph->yscale->ticks->Set(10,5);
 
$graph->axis->SetFont(FF_FONT1,FS_BOLD);
$graph->axis->SetWeight(2);
 
// Uncomment the following lines to also show grid lines.
$graph->grid->SetLineStyle('dashed');
$graph->grid->SetColor('navy@0.5');
$graph->grid->Show();
 
$graph->ShowMinorTickMarks();
$graph->SetTitles($y);
 
foreach ($xy as $key => $value) {
    $rplot = new RadarPlot(array_values($xy[$key]));
    $aGroupRadarPlot[] = $rplot;
}
 
$graph->Add($aGroupRadarPlot);
 
 
    $graph->stroke();
 
}
 
?>
Que dois-je modifier pour le rendre fonctionnel ?

Merci
mbagiella est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/07/2011, 17h09   #2
Membre régulier
 
Avatar de ypcman
 
Homme Yves
Responsable en conduite du changement
Inscription : janvier 2011
Messages : 63
Détails du profil
Informations personnelles :
Nom : Homme Yves
Localisation : France

Informations professionnelles :
Activité : Responsable en conduite du changement
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : janvier 2011
Messages : 63
Points : 73
Points : 73
bonjour.
Je trouve que tu te compliques bien le code source

j'ai juste remplacé dans l'exemple radarex6.1.php fourni dans la doc, les données initiales par les tiennes. Ça donne :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
// Some data to plot
$data = array(25,30,40,50,15);
$data2 = array(10,20,50,15,30);
 
// Create the graph and the plot
$graph = new RadarGraph(300,300);
 
// Add a drop shadow to the graph
$graph->SetShadow();
 
// Create the titles for the axis
$titles=array('A','B','C','D','E');
$graph->SetTitles($titles);
$graph->SetColor('lightyellow');
 
// ADjust the position to make more room
// for the legend
$graph->SetCenter(0.4,0.55);
$graph->SetSize(0.6);
 
// Add grid lines
$graph->grid->Show();
$graph->grid->SetColor('darkred');
$graph->grid->SetLineStyle('dotted');
 
$plot = new RadarPlot($data);
$plot->SetFillColor('lightblue');
$plot->SetLegend("Exemple");
 
$plot2 = new RadarPlot($data2);
$plot2->SetLegend("Objectif");
$plot2->SetColor('red');
$plot2->SetFill(false);
$plot2->SetLineWeight(2);
 
 
// Add the plot and display the graph
$graph->Add($plot);
$graph->Add($plot2);
$graph->Stroke();
et en image


Il te reste donc à faire en sorte de remplacer automatiquement tes données issues de ta bdd par celles que tu as fournis en exemple.
Images attachées
Type de fichier : png radar_01.png (5,6 Ko, 22 affichages)
ypcman est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/07/2011, 13h27   #3
Invité de passage
 
Homme
Administrateur de base de données
Inscription : mars 2011
Messages : 21
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : Suisse

Informations professionnelles :
Activité : Administrateur de base de données
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : mars 2011
Messages : 21
Points : 0
Points : 0
Oui en effet c'est plus simple comme cela et même fonctionnel, par contre mes besoins sont plus complexe que cela.

Dans ton exemple, il faut supposer qu'il y a deux mesure (data et data2) alors que dans mon besoins d'application il pourrait en avoir qu'une, voir plusieurs.

C'est pour cela que je suis obligé de passer par une boucle for ou while, c'est là ou c'est compliqué

J'avais mis les données data et data2 à titre d'exemple seulement, mais en vrais je vais chercher mes données directement dans ma base.
mbagiella est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/07/2011, 20h40   #4
Membre régulier
 
Avatar de ypcman
 
Homme Yves
Responsable en conduite du changement
Inscription : janvier 2011
Messages : 63
Détails du profil
Informations personnelles :
Nom : Homme Yves
Localisation : France

Informations professionnelles :
Activité : Responsable en conduite du changement
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : janvier 2011
Messages : 63
Points : 73
Points : 73
Effectivement, c'est un peu plus compliqué, mais ça reste faisable.
J'ai codé un script qui utilise une fonction. Ainsi, tu n'as plus qu'à modifier les arguments de la fonction en fonction de ton besoin.
Le point compliqué, c'était le nombre variable de radars et de valeurs pour chaque radar, mais ça fonctionne.
A titre d'exemple, 2 graphes réalisés avec le même script en changeant seulement les valeurs d'entrées :

Et le script correspondant :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require_once("../include/Util.php");
require_once ('../include/jpgraph/jpgraph.php');
require_once ('../include/jpgraph/jpgraph_radar.php');
 
$dim_x_graphe='300';
$dim_y_graphe='300';
 
$titre="titre 1";
$color_fond_graphe="lightyellow";
$color_fond_radar="white";
$tab_legend=array('A','B','C','D','E');
$tab_data=array(
array("Objectifs","black",'70','80','65','90','75'),
array("zone 1","blue",'50','30','55','60','50'),
array("zone 2","green",'40','52','45','70','60'),
array("zone 3","red",'55','60','47','86','65'),
array("zone 4","gray",'65','71','63','65','40'));
/*
$titre="titre 2";
$color_fond_graphe="lightyellow";
$color_fond_radar="black";
$tab_legend=array('Nord','Ouest','Sud','Est');
$tab_data=array(
array("Objectifs","black",'70','80','65','90'),
array("essai 1","blue",'50','30','55','60'),
array("essai 2","green",'40','52','45','70'),);
*/
/////////////////////////////////////////////////////////////////////////
radar_multiple($dim_x_graphe,$dim_y_graphe,$titre,
$color_fond_graphe,$color_fond_radar,$tab_legend,&$tab_data);
 
function radar_multiple($dim_x_graphe,$dim_y_graphe,$titre
,$color_fond_graphe,$color_fond_radar,$tab_legend,$tab_data)
{
$graph = new RadarGraph($dim_x_graphe,$dim_y_graphe);
$graph->SetShadow();
$graph->SetTitles($tab_legend);
$graph->SetColor($color_fond_graphe);
$graph->SetCenter(0.45,0.55);
$graph->SetSize(0.6);
$graph->grid->Show();
$graph->grid->SetColor('darkred');
$graph->grid->SetLineStyle('dotted');
$debut='1';
foreach($tab_data AS $tab_data__)
	{
	$legend=$tab_data__[0];
	$color=$tab_data__[1];
	$tab_data_temp=array_slice($tab_data__,2);
	$plot = new RadarPlot($tab_data_temp);
	$plot->SetLegend($legend);
	$plot->SetColor($color);
	$plot->SetFill(false);
	if ($debut=='1')
		{
		$debut='0';
		$plot->SetFill(true);
		$plot->SetFillColor($color_fond_radar);
		}
	$graph->Add($plot);
	unset($tab_data_temp);
	unset($plot);
	}
$graph->Stroke();
}
?>
Si ta requête retourne des champs de la forme : légende,couleur,val1,val2,..,valx, pour extraire tes données de ta bdd, utilise une simple boucle while du genre :
Jen'ai pas pu tester car je n'ai pas ta bdd ...
Code :
1
2
3
4
5
6
7
8
9
10
11
12
 
$resultat_SELECT = mysql_query (requete_SELECT, $connexion);
$nb_val=mysql_num_cols= $resultat_SELECT;
while ($tabVal = mysql_fetch_row ($resultat_SELECT))
    {
    $tab_data[][0]=$tabval[0]; // la légende
    $tab_data[][1]=$tabval[1]; // la couleur
    for ($indice=2;indice<$nb_val+2;$indice++)
       {
        $tab_data[][$indice]=$tabval[$indice-1]; // les valeurs
        }
    }
Et voilà.
Images attachées
Type de fichier : png radar_1.png (6,9 Ko, 17 affichages)
Type de fichier : png radar_2.png (5,3 Ko, 15 affichages)
ypcman est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/09/2011, 13h36   #5
Invité de passage
 
Homme
Administrateur de base de données
Inscription : mars 2011
Messages : 21
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : Suisse

Informations professionnelles :
Activité : Administrateur de base de données
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : mars 2011
Messages : 21
Points : 0
Points : 0
Désolé pour la tardive réponse, oui merci pour cet illustration

JPgraph ne gère t'il pas des thèmes de couleurs pour les radars ?

Merci
mbagiella est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 00h06.


 
 
 
 
Partenaires

Hébergement Web