je vous explique mon soucis :
j'ai un fichier au format CSV, je dois en extraire des données précise.
Pour cela je les stocke dans un tableau en php :
Code : Tout sélectionner
<?php
## Stockage du fichier csv dans un tableau grâce à parse_csv_file ##
{
function parse_csv_file($file, $columnheadings = false, $delimiter = ',', $enclosure = "\"") {
$row = 1;
$rows = array();
$handle = fopen($file, 'r');
while (($data = fgetcsv($handle, 1000, $delimiter, $enclosure )) !== FALSE) { /
if (!($columnheadings == "false") && ($row == 1)) {
$headingTexts = $data;
} elseif (!($columnheadings == "false")) {
foreach ($data as $key => $value) {
unset($data[$key]);
$data[$headingTexts[$key]] = $value;
}
$rows[] = $data;
} else {
$rows[] = $data;
}
$row++;
}
fclose($handle);
return $rows;
}
$csv = parse_csv_file('tableau_valeurs.csv', true, ',');
?>
Code : Tout sélectionner
<?php
$heures = array(
'00h00', '00h15', '00h30', '00h45', '01h00', '1h15', '1h30', '1h45', '2h00', '2h15', '2h30', '2h45', '3h00', '3h15', '3h30', '3h45', '4h00', '4h15', '4h30', '4h45', '5h00', '5h15', '5h30', '5h45', '6h00', '6h15', '6h30', '6h45', '7h00', '7h15', '7h30', '7h45', '8h00', '8h15', '8h30', '8h45', '9h00', '9h15', '9h30', '9h45', '10h00', '10h15', '10h30', '10h45', '11h00', '11h15', '11h30', '11h45', '12h00', '12h15', '12h30', '12h45', '13h00', '13h15','13h30', '13h45', '14h00', '14h15', '14h30', '14h45', '15h00', '15h15', '15h30', '15h45', '16h00', '16h15', '16h30', '16h45', '17h00', '17h15', '17h30', '17h45', '18h00', '18h15', '18h30', '18h45', '19h00', '19h15', '19h30', '19h45', '20h00', '20h15', '20h30', '20h45', '21h00', '21h15', '21h30', '21h45', '22h00', '22h15', '22h30', '22h45', '23h00', '23h15', '23h30', '23h45', '00h00'
);
?>
j'ai ce code :
Code : Tout sélectionner
<?php
## Tracage du graphe ##
require_once "...\LinePlot.class.php";
$graph = new Graph(600, 400);
$graph->setAntiAliasing(TRUE);
#### $values = array(1, 7, 3, 2.5, 5, -4.5, -5); ####
$plot = new LinePlot($values);
$plot->setBackgroundColor(new Color(245, 245, 245));
$plot->hideLine(TRUE);
$plot->setFillColor(new Color(180, 180, 180, 75));
$plot->grid->setBackgroundColor(new Color(235, 235, 180, 60));
$plot->yAxis->setLabelPrecision(2);
$plot->yAxis->setLabelNumber(6);
$heures = array(
'00h00', '00h15', '00h30', '00h45', '01h00', '1h15', '1h30', '1h45', '2h00', '2h15', '2h30', '2h45', '3h00', '3h15', '3h30', '3h45', '4h00', '4h15', '4h30', '4h45', '5h00', '5h15', '5h30', '5h45', '6h00', '6h15', '6h30', '6h45', '7h00', '7h15', '7h30', '7h45', '8h00', '8h15', '8h30', '8h45', '9h00', '9h15', '9h30', '9h45', '10h00', '10h15', '10h30', '10h45', '11h00', '11h15', '11h30', '11h45', '12h00', '12h15', '12h30', '12h45', '13h00', '13h15','13h30', '13h45', '14h00', '14h15', '14h30', '14h45', '15h00', '15h15', '15h30', '15h45', '16h00', '16h15', '16h30', '16h45', '17h00', '17h15', '17h30', '17h45', '18h00', '18h15', '18h30', '18h45', '19h00', '19h15', '19h30', '19h45', '20h00', '20h15', '20h30', '20h45', '21h00', '21h15', '21h30', '21h45', '22h00', '22h15', '22h30', '22h45', '23h00', '23h15', '23h30', '23h45', '00h00'
);
$plot->xAxis->setLabelText($heures);
$plot->setSpace(6, 6, 10, 10);
$graph->add($plot);
$graph->draw();
}
?>
En gros modifié cette ligne :
Code : Tout sélectionner
#### $values = array(1, 7, 3, 2.5, 5, -4.5, -5); ####Pour résumé :
j'ai deux tableaux :
_ un qui contient des heures (celui ci on s'en occupe pas)
_ un qui est obtenu à partir d'un CSV, il contient plusieurs colonne :
Patate / Tomate / Concombre / Fromage
et chaqu'une de ces colonne contient des valeurs
Je veut juste qu'il me sélectionne la colonne Tomate (par exemple) et qu'il me trace le graphe en fonction des heures
voilà si vous pouviez m'aider car j'arrive pas à comprendre comment on fait ça ???
PS : le code Tracage du graphes est obtenu avec Artichow