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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
| <?php
include $_SERVER['DOCUMENT_ROOT'] .'/jpgraph/src/jpgraph.php';
include $_SERVER['DOCUMENT_ROOT'] .'/jpgraph/src/jpgraph_bar.php';
try{
$bildX=800;
$bildY=900;
// Create the graph. These two calls are always required
$graph = new Graph($bildX,$bildY,"auto");
//Added for 4.0
$graph->ClearTheme();
$graph->SetScale("textint");
// Rotate graph 90 degrees and set margin
$graph->Set90AndMargin(160,15,45,40);
$dataCountry = array (
0 => 'BELGIUM',
2 => 'FRANCE',
3 => 'GERMANY'
);
$dataGender = array (
0 => 'female',
1 => 'male');
$dataCountryColor = array(
'BELGIUM' => 'dodgerblue4',
'FRANCE' => 'coral',
'GERMANY' => 'darkorchid');
$dataCountryGender =array (
'BELGIUM' =>array ('female' => 1,'male' => 2),
'FRANCE' => array ('female' => 3,'male' => 4),
'GERMANY' => array('female' => 5,'male' => 1)
);
// construct the different dataY
foreach($dataCountry AS $country){
foreach($dataGender AS $gender){
if(empty($dataCountryGender[$country][$gender]))$dataCountryGender[$country][$gender]='';
$dataY[$gender][] = $dataCountryGender[$country][$gender];
$dataYcolor[$gender][] = $dataCountryColor[$country];
}
$dataX[] = $country;
}
foreach($dataY AS $key => $value){
$bplot[$key] = new BarPlot($dataY[$key]);
$bplot[$key]->SetWidth(1.0);
# value shown for the bar
$bplot[$key]->value->Show();
$bplot[$key]->value->SetColor('white');
$bplot[$key]->SetValuePos('center');
$bplot[$key]->value->SetFormat('%d');
$bplot[$key]->value->SetFont(FF_ARIAL,FS_BOLD,10);
$bplot[$key]->SetFillColor($dataYcolor[$key]);
switch($key){
case 'female':
$bplot[$key]->SetPattern(PATTERN_CROSS1,'gray');
break;
case 'male':
break;
case 'f->m':
$bplot[$key]->SetPattern(PATTERN_STRIPE1,'red');
break;
case 'm->f':
$bplot[$key]->SetPattern(PATTERN_STRIPE2,'black');
break;
case 'unknown':
$bplot[$key]->SetPattern(PATTERN_DIAG1,'gray');
break;
default:
die('error, unknown gender '.$key);
}
//Error come from here
$bplot[$key]->SetLegend($key);
$AccBarPlotArray[] = $bplot[$key];
}
// Create the grouped bar plot
$gbplot = new AccBarPlot($AccBarPlotArray);
// ...and add it to the graPH
$graph->Add($gbplot);
// Setup the titles
// Setup the titles
$graph->title->Set('Nationality 2016');
$graph->title->SetMargin(10);
$graph->title->SetFont(FF_ARIAL,FS_BOLD,14);
$graph->footer->right->Set('imprimé le '.date('d.m.Y') );
$graph->footer->right->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->legend->SetFont(FF_ARIAL,FS_NORMAL,15);
$graph->legend->SetLineSpacing(7);
$graph->legend->SetShadow(FALSE);
$graph->xaxis->SetTickLabels($dataX);
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,9);
$graph->yaxis->SetPos('max');
$graph->yaxis->SetLabelSide(SIDE_RIGHT);
$graph->yaxis->SetTickSide(SIDE_LEFT);
$graph->yaxis->SetLabelMargin(15);
$graph->yaxis->scale->SetGrace(5);
$graph->Stroke();
/*
include $_SERVER['DOCUMENT_ROOT'] .'/tcpdf/tcpdf_utils.php';
$image = $graph->Stroke(_IMG_HANDLER);
$pdf= new TCPDF_UTILS();
$pdf->AddPage('L','mm','A4');
$impath=tempnam(sys_get_temp_dir(),'country');
imagepng ($image,$impath);
$size=getimagesize($impath);
$pdf->Image($impath,10,20,260,'','PNG');
unlink($impath);
imagedestroy($image);
$pdf->Output();
*/
}
catch (Throwable $t){
var_dump($t);
} |
Partager