簡體   English   中英

在另一頁中渲染PHP的TeeChart

[英]Render TeeChart for PHP in another page

我是TeeChart for PHP的新手。

我發現的所有示例都將圖表呈現在已創建圖表的同一個php文件中。

我想使用一個PHP腳本構建該圖表,該腳本通過AJAX接收一些參數,然后在生成AJAX調用的頁面上呈現該圖表。

那可能嗎? 有什么例子嗎?

最好的祝福。

傑姆·傑夫曼(Jayme Jeffman)

這里有個簡單的例子:

getchart.php:

<?php
  // get the q parameter from URL
$q = $_REQUEST["q"];


//Includes
include "../../sources/TChart.php";

$chart1 = new TChart(600,450);
$chart1->getChart()->getHeader()->setText($q);
$chart1->getAspect()->setView3D(false);

$line1 = new Line($chart1->getChart());
$line1->setColor(Color::RED());
$chart1->addSeries($line1);

// Speed optimization
$chart1->getChart()->setAutoRepaint(false);

for($t = 0; $t <= 10; ++$t) {
  $line1->addXY($t, (10 + $t), Color::RED());
}

$chart1->getChart()->setAutoRepaint(true);

$chart1->render("chart1.png");    
$rand=rand();
echo "chart1.png?rand=".$rand;
?>

的test.html:

<!DOCTYPE html>
<html>
<head>
<script>
function showChart(str) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {           
            var image = document.getElementById("get_img");
            image.src = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", "getchart.php?q="+str, true);
    xmlhttp.send();
} 
</script>
</head>
<body>

<p><b>Enter the chart title below:</b></p>
<form>
Chart title: <input type="text" onkeyup="showChart(this.value)">
</form>
<p><img id="get_img" /></p>
</body>
</html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM