Second axe Y JPgraph

Résolu
Utilisateur anonyme - 8 mars 2019 à 23:53
 Utilisateur anonyme - 10 mars 2019 à 15:29
Bonjour,

J'ai crée 2 graphiques (en barre) me permettant de voir des températures intérieure, extérieure, et la luminosité en lux; cependant, la luminosité pouvant facilement atteindre plus de 100 lux, j'ai décider de crée un 2e axe Y pour y mettre les valeurs de la luminosité.

J'ai beaucoup chercher et avec prise de tête je viens donc ici

Voici donc les codes :

$myarray = array($Valeurs[1],$Valeurs[2],$Valeurs[3]*$multilux);

// Create the graph. These two calls are always required
$graph = new Graph(720,480,'auto');
$graph->SetScale("textlin");

$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);

$graph->yaxis->SetTickPositions(array(0,5,10,15,20,25,30,35,40,45,50,55,60,65), array(15,45,75,105,135));
$graph->SetBox(false);

$graph->ygrid->SetFill(false);
$graph->xaxis->SetTickLabels(array('Température extérieur','Température intérieur','Lux'));
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);

// Create the bar plots
$b1plot = new BarPlot($myarray);

// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot));
// ...and add it to the graPH
$gbplot->SetWidth(0.5);
$graph->Add($gbplot);


$b1plot->SetColor("white");
$b1plot->SetFillColor("#cc1111");

$graph->title->Set("Données actuelles");

// Display the graph
$graph->Stroke();


Et le second graphique :

$tempINT = array($valti[0],$valti[1],$valti[2],$valti[3],$valti[4],$valti[5],$valti[6],$valti[7]);
$tempEXT = array($valte[0],$valte[1],$valte[2],$valte[3],$valte[4],$valte[5],$valte[6],$valte[7]);
$valLux = array($valux[0],$valux[1],$valux[2],$valux[3],$valux[4],$valux[5],$valux[6],$valux[7]);

// Create the graph. These two calls are always required
$graph = new Graph(850,620,'auto');
$graph->SetScale("textlin");

$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);

$graph->yaxis->SetTickPositions(array(0,5,10,15,20,25,30,35,40,45), array(15,45,75,105,135,165,195,225));
$graph->SetBox(false);

$graph->ygrid->SetFill(false);
$graph->xaxis->SetTickLabels(array($tempsh[0]."h".$tempsmin[0],$tempsh[1]."h".$tempsmin[1],$tempsh[2]."h".$tempsmin[2],$tempsh[3]."h".$tempsmin[3],$tempsh[4]."h".$tempsmin[4],$tempsh[5]."h".$tempsmin[5],$tempsh[6]."h".$tempsmin[6],$tempsh[7]."h".$tempsmin[7]));
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);

// Create the bar plots
$b1plot = new BarPlot($tempINT);
$b2plot = new BarPlot($tempEXT);
$b3plot = new BarPlot($valLux);

// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot,$b2plot,$b3plot));
$gbplot->SetWidth(0.5);
// ...and add it to the graPH
$graph->Add($gbplot);


$b1plot->SetColor("white");
$b1plot->SetFillColor("#cc1111");
$b1plot->SetLegend('Température intérieur');

$b2plot->SetColor("white");
$b2plot->SetFillColor("#11cccc");
$b2plot->SetLegend('Température extérieur');

$b3plot->SetColor("white");
$b3plot->SetFillColor("#1111cc");
$b3plot->SetLegend('Lux (x'.$multilux.')');

$graph->title->Set("Historique de données");
$graph->legend->SetFrameWeight(1);
$graph->legend->Pos(0.28,0.92);

// Display the graph
$graph->Stroke();


Si quelqu'un pourrait m'aider ce serais génial, merci pour toutes réponses ^^

2 réponses

jordane45 Messages postés 38161 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 5 mai 2024 344
9 mars 2019 à 10:38
Bonjour,

Pourrais tu nous décrire précisément le souci rencontré ?


0
Utilisateur anonyme
9 mars 2019 à 11:21
Bonjour,

Le problème c'est que j'ai 2 graphiques : un graphique en barre et un graphique en barre mais avec 3 barres (1 pour la température intérieure, température extérieure, et la luminosité), j'aimerais mettre en place un second axe Y (sur la droite) avec les valeurs de la luminosité (étant donné que la température varie de 0 à 30° alors que la luminosité varie entre 0 et 1000 Lux, c'est pour ça que j'aimerais créer un second axe sur les 2 graphiques

Je mettrais des images quand je rentrerais chez moi
0
jordane45 Messages postés 38161 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 5 mai 2024 344
9 mars 2019 à 11:31
0
Utilisateur anonyme
9 mars 2019 à 11:54
J'ai déjà consulter cette page, et celle ci est destiné au graphique en ligne, cependant j'aimerais ajouter un 2e axe Y dans des graphiques en barre
0
Utilisateur anonyme
9 mars 2019 à 22:05


Ci dessus une photo des codes exposé dans la question, en espérant que ça aide à comprendre
0
Utilisateur anonyme
10 mars 2019 à 15:29
Bon, j'ai réussi à bricoler un truc, c'est pas forcément ce que je voulais mais ça me va
Si quelqu'un aurait besoin, je met les codes finaux :

$tempiarray = array($Valeurs[1]);
$tempearray = array($Valeurs[2]);
$luxarray = array($Valeurs[3]*$multilux);


// Create the graph. These two calls are always required
$graph = new Graph(720,480,'auto');
$graph->SetScale("textlin");

$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);

$graph->img->SetAntiAliasing(false);
$graph->SetBox(false);

$graph->img->SetMargin(50,50,30,70);
$graph->SetYScale(0,'lin',0,$Valeurs[3]*$multilux+($Valeurs[3]/3));

$graph->title->Set("Données actuelles");

$graph->yaxis->SetTitlemargin(28);
$graph->yaxis->title->Set("Températures");

$graph->ygrid->SetFill(false);
$graph->xaxis->SetTickLabels(' ');
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);

$graph->ynaxis[0]->title->Set("Lux");
$graph->ynaxis[0]->SetTitlemargin(44);
$graph->ynaxis[0]->HideZeroLabel();
$graph->ynaxis[0]->HideLine(false);
$graph->ynaxis[0]->HideTicks(false,false);

// Create the bar plots
$b1plot = new BarPlot($tempiarray);
$b2plot = new BarPlot($tempearray);
$b3plot = new BarPlot($luxarray);

$b1plot->SetColor('white');
$b1plot->SetFillColor('blue');
$b1plot->SetLegend('Température intérieur');

$b2plot->SetColor('white');
$b2plot->SetFillColor('red');
$b2plot->SetLegend('Température extérieur');

$b3plot->SetColor('white');
$b3plot->SetFillColor('green');
$b3plot->SetLegend('Lux');
$b3plot->SetWidth(0.15);
// $b3plot->SetWidth(10);
$b3plot->SetYBase(50);

// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot,$b2plot));
$gbplot->SetWidth(-0.3);

$graph->Add($gbplot);
$graph->AddY(0,$b3plot);

$graph->legend->SetFrameWeight(1);
$graph->legend->SetPos(0.25,0.90);

// Display the graph
$graph->Stroke();


$tempINT = array($valti[0],$valti[1],$valti[2],$valti[3],$valti[4],$valti[5],$valti[6],$valti[7]);
$tempEXT = array($valte[0],$valte[1],$valte[2],$valte[3],$valte[4],$valte[5],$valte[6],$valte[7]);
$valLux = array($valux[0]*$multilux,$valux[1]*$multilux,$valux[2]*$multilux,$valux[3]*$multilux,$valux[4]*$multilux,$valux[5]*$multilux,$valux[6]*$multilux,$valux[7]*$multilux);

// Create the graph. These two calls are always required
$graph = new Graph(850,620,'auto');
$graph->SetScale("textlin");

$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);

$graph->img->SetAntiAliasing(false);
$graph->SetBox(false);

$graph->SetMargin(50,55,30,70);
$graph->SetYScale(0,'lin');

$graph->ygrid->SetFill(false);
$graph->xaxis->SetTickLabels(array($tempsh[0]."h".$tempsmin[0],$tempsh[1]."h".$tempsmin[1],$tempsh[2]."h".$tempsmin[2],$tempsh[3]."h".$tempsmin[3],$tempsh[4]."h".$tempsmin[4],$tempsh[5]."h".$tempsmin[5],$tempsh[6]."h".$tempsmin[6],$tempsh[7]."h".$tempsmin[7]));
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);

$graph->yaxis->title->Set("Températures");
$graph->yaxis->SetTitlemargin(30);
$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);

$graph->ynaxis[0]->title->Set("Lux");
$graph->ynaxis[0]->SetTitlemargin(55);
$graph->ynaxis[0]->HideZeroLabel();
$graph->ynaxis[0]->HideLine(false);
$graph->ynaxis[0]->HideTicks(false,false);

$graph->title->Set("Historique de données");
$graph->legend->SetFrameWeight(1);
$graph->legend->Pos(0.25,0.95);

// Create the bar plots
$b1plot = new BarPlot($tempINT);
$b2plot = new BarPlot($tempEXT);
$b3plot = new BarPlot($valLux);

$b1plot->SetColor("white");
$b1plot->SetFillColor("#cc1111");
$b1plot->SetLegend('Température intérieur');

$b2plot->SetColor("white");
$b2plot->SetFillColor("#11cccc");
$b2plot->SetLegend('Température extérieur');

$b3plot->SetColor("white");
$b3plot->SetFillColor("#1111cc");
$b3plot->SetLegend('Lux');
$b3plot->SetWidth(0.2);
$b3plot->SetYBase(50);

// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot,$b2plot));
$gbplot->SetWidth(-0.4);

$graph->Add($gbplot);
$graph->AddY(0,$b3plot);

// Display the graph
$graph->Stroke();
0
Rejoignez-nous