ciao, ho trovato su http://php.html.it/articoli/leggi/92...php-con-ming/6 un interessante metodo per far disegnare un grafico ad una pagina php. Però, non so perchè, io non ci riesco nemmeno seguendo passo a passo l'esempio ossi creando una pagina mggraph_vbar.class.php con questo codice:
Codice PHP:
<?php
class MGGraph_VBar {
function MGGraph_VBar($width, $height, $minValue, $maxValue, $numGridLines, $fontHeight, $bgColor) {
$this->width = $width;
$this->height = $height;
$this->minValue = $minValue;
$this->maxValue = $maxValue;
$this->numGridLines = $numGridLines;
$this->fontHeight = $fontHeight;
$this->bgColor = $bgColor;
}
function addBar($value, $text, $fgColor = array(200, 90, 30), $fillColor = array(20, 180, 50)) {
$this->bars[] = array(
$value,
$text,
$fgColor,
$fillColor
);
}
function &_prepareSwf() {
// Crea il filmato ed imposta alcune propietà basilari
$movie = &new SWFMovie();
$movie->setDimension($this->width, $this->height);
$movie->setBackground($this->bgColor[0], $this->bgColor[1], $this->bgColor[2]);
// Instanzia il font di default
$font = new SWFFont('fdb/Bitstream Vera Sans.fdb');
// Inizializza un oggetto TEXT che verrà usato per
// calcolare le lunghezze del testo
// Instanzio l'oggetto
$text = new SWFText();
// Imposto il font da usare e l'altezza del testo
$text->setFont($font);
$text->setHeight($this->fontHeight);
// Calcola alcune misure
$YValueWidth = $text->getwidth($this->maxValue) + 20;
$maxHeightUsable = $this->height - (10 + 41 + 5);
// Inizializza lo shape
$grid = &new SWFShape();
$grid->setLine(2, 10, 10, 10);
// Disegna l'asse verticale
$grid->movePenTo($YValueWidth, 10);
$grid->drawLineTo($YValueWidth, $this->height - 10);
// Disegna l'asse orizzontale
$grid->movePenTo(10, $this->height - 40);
$grid->drawLineTo($this->width - 10, $this->height - 40);
// Aggiunge la griglia all'oggetto MOVIE
$movie->add($grid);
// Instanzia l'oggetto ed imposta le proprietà
$gridHLines = &new SWFShape();
$gridHLines->setLine(1, 30, 30, 30);
// Esegue alcune misurazioni
$gridVertDistance = ($maxHeightUsable / $this->numGridLines);
$vertInterval = ($this->maxValue - $this->minValue) / $this->numGridLines;
$currValue = $this->minValue;
// Aggiunge il testo del punto zero
$tmpYPos = $this->height - 40 + 1 + $this->fontHeight;
$tmpTEXT = &new SWFText();
$tmpTEXT->setFont($font);
$tmpTEXT->setHeight($this->fontHeight);
$tmpTEXT->setColor(0, 0, 0);
$tmpTEXT->moveTo($YValueWidth - (2 + ($text->getwidth($currValue))), $tmpYPos);
$tmpTEXT->addstring($currValue);
$movie->add($tmpTEXT);
$currValue += $vertInterval;
for ($currLine = 1; $currLine <= $this->numGridLines; $currLine++) {
// Calcola la posizione Verticale della linea
$tmpYPos = $this->height - (41 + ($gridVertDistance * $currLine));
// Aggiunge la linea
$gridHLines->movePenTo($YValueWidth, $tmpYPos);
$gridHLines->drawLineTo($this->width - 10, $tmpYPos);
// Aggiunge il testo
$tmpTEXT = &new SWFText();
$tmpTEXT->setFont($font);
$tmpTEXT->setHeight($this->fontHeight);
$tmpTEXT->setColor(0, 0, 0);
if ($currLine == $this->numGridLines) {
$tmpTEXT->moveTo($YValueWidth - (2 + ($text->getwidth($this->maxValue))), $tmpYPos + (int)($this->fontHeight/2) -1 );
$tmpTEXT->addstring($this->maxValue);
} else {
$tmpTEXT->moveTo($YValueWidth - (2 + ($text->getwidth(ceil($currValue)))), $tmpYPos + (int)($this->fontHeight/2) -1 );
$tmpTEXT->addstring(ceil($currValue));
}
$movie->add($tmpTEXT);
// Incrementa il valore corrente
$currValue += $vertInterval;
}
// Aggiunge la griglia delle linee orizzontali al filmato
$movie->add($gridHLines);
// Imposta alcuni valori iniziali
$dispWidth = $this->width - ($YValueWidth + 2 + 10 + 30);
$widthForBar = $dispWidth / count($this->bars);
$leftPosition = $YValueWidth + 2 + 15;
$baseYPos = $this->height - 40 - 1;
// Cicla l'elenco di barre verticali da visualizzare a video
while(list(, $vBar) = each($this->bars)) {
// Calcola l'altezza della barra
if ($vBar[0] == $this->minValue) {
// Se il valore è uguale al valore minimo
// l'altezza è uguale a zero
$heightBar = 0;
} else {
// Se il valore della barra è maggiore del valore minimo
// Calcola l'altezza in pixel della barra
$heightBar = (($vBar[0] - $this->minValue) / ($this->maxValue - $this->minValue)) * $maxHeightUsable;
}
// Aggiunge la barra verticale
$tmpSHAPE = &new SWFShape();
$tmpSHAPE->setLine(1, $vBar[2][0], $vBar[2][1], $vBar[2][2]);
$tmpSHAPE->setRightFill($tmpSHAPE->addFill($vBar[3][0], $vBar[3][1], $vBar[3][2], isset($vBar[3][3]) ? $vBar[3][3] : 220 ));
$tmpSHAPE->movePenTo($leftPosition + 5, $baseYPos);
$tmpSHAPE->drawLineTo($leftPosition + 5, $baseYPos - $heightBar);
$tmpSHAPE->movePenTo($leftPosition + 5, $baseYPos - $heightBar);
$tmpSHAPE->drawLineTo($leftPosition + $widthForBar - 5, $baseYPos - $heightBar);
$tmpSHAPE->movePenTo($leftPosition + $widthForBar - 5, $baseYPos - $heightBar);
$tmpSHAPE->drawLineTo($leftPosition + $widthForBar - 5, $baseYPos);
// Aggiungo lo shape al filmato
$movie->add($tmpSHAPE);
// Aggiunge il testo
$tmpTEXT = &new SWFText();
$tmpTEXT->setFont($font);
$tmpTEXT->setHeight($this->fontHeight);
$tmpTEXT->setColor($vBar[2][0], $vBar[2][1], $vBar[2][2]);
$tmpTEXT->moveTo(($leftPosition + ($widthForBar / 2)) - ($tmpTEXT->getWidth($vBar[1]) / 2), $this->height - 40 + 1 + $this->fontHeight);
$tmpTEXT->addstring($vBar[1]);
$movie->add($tmpTEXT);
// Sposto il cursore verso destra
$leftPosition += $widthForBar;
}
}
function save($filename) {
$movie = &$this->_prepareSwf();
$movie->save($filename);
}
function output() {
$movie = &$this->_prepareSwf();
header('Content-type: application/x-shockwave-flash');
$movie->output(9);
flush();
}
}
?>
e una pagine index.php con quest'altro codice:
Codice PHP:
<?php
require_once('mggraph_vbar.class.php');
$MGGraph_VBar = &new MGGraph_VBar(
600, // Larghezza
300, // Altezza
500, // Valore minimo
2000, // Valore massimo
10, // Numero di linee nella griglia
12, // Dimensione font in pixel
array (
240, // Componente ROSSO del colore di sfondo
240, // Componente VERDE del colore di sfondo
240 // Componente BLU del colore di sfondo
)
);
$MGGraph_VBar->addBar(708, "Gen");
$MGGraph_VBar->addBar(1200, "Feb");
$MGGraph_VBar->addBar(600, "Apr");
$MGGraph_VBar->addBar(1400, "Mar", array(10, 50, 180), array(200, 10, 10, 80));
$MGGraph_VBar->addBar(1500, "Mag");
$MGGraph_VBar->addBar(830, "Giu");
$MGGraph_VBar->addBar(1700, "Lug");
$MGGraph_VBar->addBar(1800, "Ago");
$MGGraph_VBar->addBar(100, "Set", array(80, 150, 180), array(80, 150, 180, 90));
$MGGraph_VBar->addBar(2000, "Ott");
$MGGraph_VBar->addBar(1150, "Nov");
$MGGraph_VBar->addBar(784, "Dic");
$MGGraph_VBar->output();
?>
il risultato di tutto questo codice è che il browser cerca sempre di caricare una pagina (in loop) con le caratteristiche di Flash ma completamente bianca!!
Qualcuno mi sa dire dove ho sbagliato? grazie! Ciao