简体   繁体   English

在另一页中渲染PHP的TeeChart

[英]Render TeeChart for PHP in another page

I am a newbie on TeeChart for PHP. 我是TeeChart for PHP的新手。

All examples I have found are rendering the chart on the same php file where it has been created. 我发现的所有示例都将图表呈现在已创建图表的同一个php文件中。

I would like to build the chart using a PHP script, which receives some parameters via AJAX, and render the chart on the page which has generated the AJAX call. 我想使用一个PHP脚本构建该图表,该脚本通过AJAX接收一些参数,然后在生成AJAX调用的页面上呈现该图表。

Is that possible? 那可能吗? Any example on that? 有什么例子吗?

Best regards. 最好的祝福。

Jayme Jeffman 杰姆·杰夫曼(Jayme Jeffman)

Here a simple example: 这里有个简单的例子:

getchart.php: 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: 的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