Visualizzazione dei risultati da 1 a 9 su 9

Discussione: Problemi jpgraph

  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2001
    residenza
    rimini, san marino
    Messaggi
    934

    Problemi jpgraph

    Ciao a tutti.

    Ecco il codice del mio script:

    codice:
    <?php
    include ("/www/htdocs/jpgraph/src/jpgraph.php");
    include ("/www/htdocs/jpgraph/src/jpgraph_line.php");
    include ("/www/htdocs/jpgraph/src/jpgraph_bar.php");
    
    $zona = $_POST['zona'];
    
    $connessione = mysql_connect ($host , $user, $password);
    
    $query= "select fatturato_1,descrizione_linea from $nome_tabella where codice_agente='$zona'";
    
    $query_risultato = mysql_db_query ($nome_database, $query , $connessione);
    
          $numero_righe=mysql_num_rows($query_risultato);
    
          while ( $row = mysql_fetch_assoc( $query_risultato ) )	{
    
                     $datay[] = $row['fatturato_1'];
                     $datax[] = $row['descrizione_linea'];
    
    	}
    
    
    $graph = new graph(580,400,"auto");
    $graph->setscale("textlin");
    
    $bplot = new BarPlot($datay);
    $bplot->SetFillColor("orange");
    
    $graph->Add($bplot);
    
    $graph->Stroke();
    
    ?>
    Ecco gli errori che mi da:

    codice:
    JpGraph Error: HTTP headers have already been sent. 
    Explanation:
    HTTP headers have already been sent back to the browser indicating the data as text before the library got a chance to send it's image HTTP header to this browser. This makes it impossible for the library to send back image data to the browser (since that would be interpretated as text by the browser and show up as junk text).
    Most likely you have some text in your script before the call to Graph::Stroke(). If this texts gets sent back to the browser the browser will assume that all data is plain text. Look for any text, even spaces and newlines, that might have been sent back to the browser. 
    
    For example it is a common mistake to leave a blank line before the opening "<?php".
    Dove sto sbagliando?

    Grazie,
    Ale

  2. #2
    Utente di HTML.it
    Registrato dal
    Nov 2001
    Messaggi
    525
    come scritto, devi togliere la riga bianca prima dell'apertura del tag <?php

    NB la pagina che visualizzerà l'immagine nn deve contenere nessun echo, altrimenti t restituirà errore

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2001
    residenza
    rimini, san marino
    Messaggi
    934
    Ma scusa, se io volessi mettere questo grafico all'interno di un'altra pagina con un include non potrei?

    Ho verificato e il problema in effetti me lo da quando lo includo dentro un'altra pagina.

    Mi sembra una grossa limitazione questa. Sbaglio?

    ALe

  4. #4
    Moderatore di Server Apache L'avatar di marketto
    Registrato dal
    Sep 2001
    Messaggi
    5,858
    in grafico lo potrai richiamare successivamente tramite il tag IMG, ovvero:
    codice:
    [img]grafico.php[/img]

    think simple think ringo

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2001
    residenza
    rimini, san marino
    Messaggi
    934
    Mi trovo in difficolta.

    Continua a darmi sempre lo stesso tipo di errore.

    Nella mia pagina lavoro già con i cookie; è un problema?

    Grazie,
    Ale

  6. #6
    Moderatore di Server Apache L'avatar di marketto
    Registrato dal
    Sep 2001
    Messaggi
    5,858
    le operazioni da eseguire sono 2:
    - creare un file php per avere il grafico
    - inserire come immagine il collegamento al file del grafico


    per risolvere i problemi sono già state scritte le varie soluzioni




    think simple think ringo

  7. #7
    Utente di HTML.it
    Registrato dal
    Jul 2001
    residenza
    rimini, san marino
    Messaggi
    934
    Ecco come ho fatto io:

    questo è il file che crea il grafico:

    codice:
    <?php
    include ("/srv/www/htdocs/jpgraph/src/jpgraph.php");
    include ("/srv/www/htdocs/jpgraph/src/jpgraph_line.php");
    include ("/srv/www/htdocs/jpgraph/src/jpgraph_bar.php");
    
    $zona="2";
    
    $connessione = mysql_connect ($host , $user, $password);
    
    $query= "select fatturato_1,descrizione_linea from $nome_tabella where codice_agente='$zona'";
    
    $query_risultato = mysql_db_query ($nome_database, $query , $connessione);
    
    $st = mysql_query( $query ) or die( mysql_error() );
    while ( $row = mysql_fetch_assoc( $st ) ) {
    	$datay[] = $row['fatturato_1'];
            $datax[] = $row['descrizione_linea'];
    }
    
    $graph = new graph(580,400,"auto");
    $graph->setscale("textlin");
    
    $bplot = new BarPlot($datay);
    $bplot->SetFillColor("orange");
    
    
    
    $graph->Add($bplot);
    
    $graph->Stroke();
    
    ?>
    ecco il file che stampa il grafico:

    codice:
    <?php
    include("grafico_confronto_2.php");
    print("<img src=\"grafico_confronto_2.php\" alt=\"grafico\" >");
    Ovviamente sto sbagliando qualche cosa. ma cosa?

    Ale

    ?>

  8. #8
    Moderatore di Server Apache L'avatar di marketto
    Registrato dal
    Sep 2001
    Messaggi
    5,858
    il file grafico_confronto_2.php funziona, ovvero riesci a visualizzare il grafico? per il problema dell'header controlla di nn aver nessun tipo di output se nn le funzioni di jpgraph.

    successivamente puoi usare il tag img, senza dover includere nuovamente il file grafico_confronto_2.php.


    prova così
    think simple think ringo

  9. #9
    Utente di HTML.it
    Registrato dal
    Jul 2001
    residenza
    rimini, san marino
    Messaggi
    934
    GRazie dell'aiuto.

    Visto che ne sai , ti chiedo un altro consulto.

    Ho bisogno di fare nello stesso grafico a barre per ogni valore $data_x[] due valori $datay_1[], $datay2.

    Penso che il tutto si faccia con setpattern però non ho capito come.

    Puoi darmi qualche suggerimento per piacere?


    codice:
    while ( $row = mysql_fetch_assoc( $st ) )
    {
        $datay_1[] = $row['fatturato_1'];
        $datay_2[] = $row['fatturato_2'];
        $datax[] = $row['descrizione_linea'];
    }
    
    
    $graph = new graph(580,400,"auto");
    $graph->setscale("textlin");
    
    $bplot = new BarPlot($datay_1);
    $bplot_1 = new BarPlot($datay_2);
    
    $graph->img->setmargin(40,20,40,80);
    
    $graph->yaxis->title->set("Fatturato");
    $graph->yaxis->title->setcolor("red");
    
    $graph->xaxis->SetFont(FF_FONT1,FS_NORMAL,4);
    $graph->xaxis->SetLabelAngle(90);
    
    $graph->xaxis->setticklabels($datax);
    
    $bplot->SetLegend("Fatturato ordinato $data_anno_in_corso");
    
    $bplot->value->Show();
    
    $graph->Add($bplot);
    $graph->legend->pos(0.2,0.05,"right","center");
    
    $graph->Stroke("/srv/www/htdocs/contenuti_speciali/statistiche_ordinato/grafico_1.png");
    Rigrazie,
    Ale

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.