suchen
HeimBackend-EntwicklungPHP-Tutorial用Flash图形化数据(二)_PHP教程

用Flash图形化数据(二)_PHP教程

Jul 21, 2016 pm 04:05 PM
flashphpzweiTun图形LandErfolguns数据verwenden饼图

让我们烤点甜饼(做饼图)
成功地安装了PHP地Shockwave Flash支持后,就可以用PHP创建Shockwave文件了。学习的最好方法就是直接跳到程序去,所以下面就让我们看看程序。第一个文件包括怎样使用类的示例代码,同时也显示了如何将一个Flash文件嵌入到HTML文档中。


// include class needed for flash graph
include("class.pie.flash.php");

mysql_connect ("localhost", "root", "");

$query = "SELECT DISTINCT city_name, COUNT(city_id)
    FROM city
    GROUP BY city_name;";

$result = mysql_db_query ("hermes",$query);

while ($row = mysql_fetch_array ($result)) {
    $city_counts[] = $row["COUNT(city_id)"];
    $city_names[] = $row["city_name"];
}

mysql_free_result ($result);

// Instantiate new object
$graph = new flash_pie($city_counts, "city.swf");

// set graph title (should not exceed about 25 characters)
$graph->pie_title("City Results", 30);

// set graph legend
$graph->pie_legend($city_names);

// show graph
$graph->show();

// free resources
$graph->close();

?>  










type="application/x-shockwave-flash" width=600 height=300>


  




class flash_pie {

// class variables

// setup some global colors
var $r_arr = array(0.1,  1, 0, 1, 0, 1, 0.388235294, 0.4, 0.388235294, 0.929411765);
var $g_arr = array(1,    0, 0, 1, 1, 0, 0.8,         0.4, 0.8,         0.439215686);
var $b_arr = array(0.25, 0, 1, 0, 1, 1, 1,           0.4, 1,           0.043137255);  

var $percents;

function flash_pie($values, $this_file) { //begin constructor
    // to write out code directly to browser, set content header and use "php://stdout"
    //swf_openfile ("php://stdout", 700, 250, 30, 1, 1, 1);
    //header("Content-type: application/x-shockwave-flash");

    swf_openfile ($this_file, 1000, 450, 30, 1, 1, 1);

    // set up viewport for flash movie
    swf_ortho2 (-400, 300 , -90, 250);  

    // choose the font we will use for pie graph
    swf_definefont(10, "Mod");

    // get sum of array for percents/slices
    while(list($key,$val) = each($values)) {  
        $sum = $sum + $val;  
    }

    for ($i=0; $i        // calculate how big they need to be and then
        // draw all of our slices
        if ($i == 0) {  
            // setup parameters for first slice
            $begin = 0;
            $val = $values[$i]/$sum;
            $end = $val*360;
            swf_translate(-200, 0, 0);
        } else {
            // setup parameters for every other slice
            $begin = $end;
            $val = $values[$i]/$sum;
            $end = $end + $val*360;
        }

        // function call to add slice
        $objID = 1+$i*10;
        $this->show_slice($i, $objID, $begin, $end);

        // put together percent array for all labels
        $this->percents[$i] = round($values[$i]/$sum*100);            
    }

}  //end flash_pie

function show_slice($i, $objID, $begin, $end) {
    // draws a slice and places it in our frame
    swf_addcolor($this->r_arr[$i], $this->g_arr[$i], $this->b_arr[$i], 1);

    swf_startshape($objID);
    swf_shapefillsolid(0, 0, 0, 1);
    swf_shapearc(0, 0, 100, $begin, $end);
    swf_shapecurveto(0, 0, 0, 0);
    swf_endshape($objID);

    swf_pushmatrix();
    swf_placeobject($objID, 1);
    swf_popmatrix();
    swf_showframe();
}


function pie_legend($labels) {
    // draws the legend and labels and places it in our frame
    for ($i=0; $i        swf_addcolor($this->r_arr[$i], $this->g_arr[$i], $this->b_arr[$i], 1);

        swf_definerect($i+1000, 1, 0, 20, 20, 0);
        if ($i == 0) {
            swf_translate(120, 75, 0);
        } else {
            swf_translate(0, 20, 0);
        }
        swf_placeobject($i+1000, 1);

        swf_translate(0, 5, 0);
        unset($label);
        $label = $labels[$i];
        $label .= " (";
        $label .= $this->percents[$i];
        $label .= " percent)";
        if ($i==0) {
            $width = (swf_textwidth($label)/4)+30;
        } else {
            $width = round(swf_textwidth($label)/2)+30;
        }
        $this->pie_text($i-1000, "$label", 15, $width, 0);
        swf_translate(-$width, 0, 0);
    }
    swf_translate($width, 30*count($labels), 0);
}                


function pie_text($id, $text, $size, $x, $y) {
    // simple function to draw text ($text) at ($x,$y) with font size ($size)
    // set color of text to black
    swf_addcolor(0,0,0,0);

    // set font size and slant
    swf_fontsize($size);
    swf_fontslant(0);

    // define, position and place text in frame
    swf_definetext($id, "$text", 1);
    swf_translate($x, $y, 0);
    swf_placeobject($id, 1);
}

function pie_title($text, $size) {
    // simple function to draw title and set lineup
    // $text should not exceed about 25 characters
    $this->pie_text(99, $text, $size, 0, 150);
    swf_translate(0, -300, 0);
}        

function show() {
    // show the frame
    swf_showframe();
}


function close() {
    // flush our buffer and return movie
    $data = swf_closefile(1);
}                

} // end class flash_pie

?>  

    注意,你可以将生成的SWF文件直接返回到浏览器中,而不必一定要像我一样把它写到一个文件中。这可能对测试来说是有用的,但你可能很少用到一个Flash文件,更多的时候你可能想把Flash文件嵌入到HTML文档中。如果你选择直接把Flash文件输出到浏览器中,你可以如下设置header content 类型:
   header("Content-type: application/x-shockwave-flash")
并把swf_openfile(filename",...)改成swf_openfile("php://stdout",...)

更多信息的链接:
    http://www.php.net/manual/ref.swf.php  关于swf_* PHP函数的说明
    http://reality.sgi.com/grafica/flash/  下载PHP的swf库
    http://openswf.org                     更多Flash工具和信息
    http://www.macromedia.com/software/flash/open/licensing/  
                                           关于Macromedia Flash SDK的更多信息 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/315804.htmlTechArticle让我们烤点甜饼(做饼图) 成功地安装了PHP地Shockwave Flash支持后,就可以用PHP创建Shockwave文件了。学习的最好方法就是直接跳到程序去,...
Stellungnahme
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
PHP -Abhängigkeitsinjektionsbehälter: Ein schneller StartPHP -Abhängigkeitsinjektionsbehälter: Ein schneller StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesClass -Abhängigkeiten, EnhancingCodemodularität, Testbarkeit und Maschinenbarkeit.

Abhängigkeitsinjektion im Vergleich zum Service -Locator in PHPAbhängigkeitsinjektion im Vergleich zum Service -Locator in PHPMay 13, 2025 am 12:10 AM

Wählen Sie die Abhängigkeitsinjektion (DI) für große Anwendungen. Der Servicelocator ist für kleine Projekte oder Prototypen geeignet. 1) DI verbessert die Testbarkeit und Modularität des Codes durch Konstruktorinjektion. 2) Servicelocator erhält Dienstleistungen durch die Zentrumregistrierung, was bequem ist, aber zu einer Erhöhung der Codekupplung führen kann.

PHP -Leistungsoptimierungsstrategien.PHP -Leistungsoptimierungsstrategien.May 13, 2025 am 12:06 AM

PhpapplicationscanbeoptimizedforspeedandefficiencyBy: 1) EnabgingOpcacheinphp.ini, 2) usePreparedStatementsWithpdoFordatabasequeries, 3) Ersatzloopswitharray_Filterandarray_mapfordataprozessing, 4) Konfigurieren von), 4), implementieren, 5)

PHP -E -Mail -Validierung: Stellen Sie sicher, dass E -Mails korrekt gesendet werdenPHP -E -Mail -Validierung: Stellen Sie sicher, dass E -Mails korrekt gesendet werdenMay 13, 2025 am 12:06 AM

PhpemailvalidationInvolvesthreesteps: 1) Formatvalidationusing -RegularexpressionStocheckTheemailformat; 2) DnsvalidationToensurethedomainhasavalidmxRecord;

So machen Sie PHP -Anwendungen schnellerSo machen Sie PHP -Anwendungen schnellerMay 12, 2025 am 12:12 AM

TomakePhpapplicationsfaster, folgt der THESESTEPS: 1) UseOpCodeCaching LikeopcachetOstorePrecompiledScriptByteCode.2) MinimizedatabasequeriesByusedQueryCachingandefficiendexing.3) Hebel -FeaturesForbetTerCodeeffizienz.4) Implementierungspflichtiger Strategie

Checkliste für PHP -Leistungsoptimierung: Verbesserung der Geschwindigkeit jetztCheckliste für PHP -Leistungsoptimierung: Verbesserung der Geschwindigkeit jetztMay 12, 2025 am 12:07 AM

ToimProvePhpapplicationSpeed, folge theSeSteps: 1) enableOpCodeCachingWithAPCUToreducescriptexexexeTime.2) ImplementDatabaseQueryCachingusedpdotominimizedatabaseHits.3) UseHttp/2TomultiplexRequeTsReconneconneconneconneconneconneconnectionOverhead.4))

PHP -Abhängigkeitsinjektion: Verbesserung der Code -TestbarkeitPHP -Abhängigkeitsinjektion: Verbesserung der Code -TestbarkeitMay 12, 2025 am 12:03 AM

Die Abhängigkeitsinjektion (DI) verbessert die Testbarkeit von PHP -Code durch explizit transitive Abhängigkeiten signifikant. 1) DI -Entkopplungsklassen und spezifische Implementierungen machen Tests und Wartung flexibler. 2) Unter den drei Typen injiziert der Konstruktor explizite Expressionsabhängigkeiten, um den Zustand konsistent zu halten. 3) Verwenden Sie DI -Container, um komplexe Abhängigkeiten zu verwalten, um die Codequalität und die Entwicklungseffizienz zu verbessern.

PHP -Leistungsoptimierung: DatenbankabfrageoptimierungPHP -Leistungsoptimierung: DatenbankabfrageoptimierungMay 12, 2025 am 12:02 AM

DatabaseQueryoPtimizationInphpinvolvesseveralStrategieShancePerformance.1) selectonlynn -nötigesColumntededatatransfer.2) Verwenden Sie IndexingTospeedUpDatarErvieval.3) ImplementQueryCachingtoStoreresultsOffRequerien.4) Nützliche Stände

See all articles

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

Video Face Swap

Video Face Swap

Tauschen Sie Gesichter in jedem Video mühelos mit unserem völlig kostenlosen KI-Gesichtstausch-Tool aus!

Heißer Artikel

Nordhold: Fusionssystem, erklärt
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
Mandragora: Flüstern des Hexenbaum
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

EditPlus chinesische Crack-Version

EditPlus chinesische Crack-Version

Geringe Größe, Syntaxhervorhebung, unterstützt keine Code-Eingabeaufforderungsfunktion

PHPStorm Mac-Version

PHPStorm Mac-Version

Das neueste (2018.2.1) professionelle, integrierte PHP-Entwicklungstool

SublimeText3 Linux neue Version

SublimeText3 Linux neue Version

SublimeText3 Linux neueste Version

WebStorm-Mac-Version

WebStorm-Mac-Version

Nützliche JavaScript-Entwicklungstools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Leistungsstarke integrierte PHP-Entwicklungsumgebung