首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在php页面中加载JpGraph

问在php页面中加载JpGraph
EN

Stack Overflow用户
提问于 2015-09-08 05:13:34
回答 1查看 539关注 0票数 1

我想使用ajax或javascript在另一个ajax页面中加载jpgraph。我在单独的php页面上成功地显示了图形,但是我想显示从Graphs.php页面到index.php页面的图形。我试过但没有成功。

index.php

代码语言:javascript
复制
$('#submitG').click(function(e) {
    e.preventDefault();
    // document.getElementById('content1').style.display = 'none';
    alert("gfh"+$('#startG').val()+$('#endG').val());
    $('#cont').load('<img src="view.png">').fadeIn("slow");
    alert("completed");
});

<form >
    <input name="startG" type="date" id="startG"  required/></div>
    <input name="endG" type="date" id="endG" required/></div>
    <input type="submit" value="Show Graph" id="submitG"/>
</form>

UPADTE:

//这是我想要加载映像的div

代码语言:javascript
复制
<div id="cont"></div>

Graphs.php

代码语言:javascript
复制
<?php
    include("DBConfig.php"); 
    require_once ('/src/jpgraph.php');
    require_once ('/src/jpgraph_line.php');
    $ph1=array();
    $ph2=array();
    $ph3=array();
    $sDate= $_POST['startDateG'];
    $eDate=$_POST['endDateG'];
    $datee1 = new DateTime($sDate);
    $date1=$datee1->format('d-m-y'); // 31-07-2012
    //echo "&nbsp;&nbsp;&nbsp;&nbsp;";
    $datee2 = new DateTime($eDate);
    $date2=$datee2->format('d-m-y'); // 31-07-2012
    if ($conn) {     
        //echo 'Connected';
        $stid = oci_parse($conn, "SELECT * FROM table");
        oci_execute($stid);
        while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
            array_push($d1, $row['c1']);
            array_push($d2, $row['c2']);
            array_push($d3, $row['c3']);
        }
    }

    $datay1 = array(20,15,23,15);
    $datay2 = array(12,9,42,8);
    $datay3 = array(5,17,32,24);

    // Setup the graph
    $graph = new Graph(1000,450);
    $graph->SetScale("textlin");

    $theme_class=new UniversalTheme;

    $graph->SetTheme($theme_class);
    $graph->img->SetAntiAliasing(false);
    $graph->title->Set('Single Pahse');
    $graph->SetBox(false);

    $graph->img->SetAntiAliasing();

    $graph->yaxis->HideZeroLabel();
    $graph->yaxis->HideLine(false);
    $graph->yaxis->HideTicks(false,false);

    $graph->xgrid->Show();
    $graph->xgrid->SetLineStyle("solid");
    $graph->xaxis->SetLabelMargin(2);
    $graph->xgrid->SetColor('#E3E3E3');

    // Create the first line
    $p1 = new LinePlot($d1);
    $graph->Add($p1);
    $p1->SetColor("#6495ED");
    $p1->SetLegend('Line 1');

    // Create the second line
    $p2 = new LinePlot($d2);
    $graph->Add($p2);
    $p2->SetColor("#B22222");
    $p2->SetLegend('Line 2');

    // Create the third line
    $p3 = new LinePlot($d3);
    $graph->Add($p3);
    $p3->SetColor("#FF1493");
    $p3->SetLegend('Line 3');

    $graph->legend->SetFrameWeight(1);

    // Output line
    $graph->Stroke();

    oci_close($conn);

?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-08 05:27:32

试着做这样的事情:

代码语言:javascript
复制
$('#submitG').click(function(e) {
    e.preventDefault();
    alert("gfh"+$('#startG').val()+$('#endG').val());
    $('#cont').load(
        'Graphs.php',
        {
            startG: $('#startG').val(),
            endG: $('#endG').val(),
        },
        function() {
            alert("completed");
            $(this).fadeIn("slow"); // Or $('#cont').fadeIn("slow");
        }
    );
});

因为jQuery.load通过GET获取数据,所以在PHP脚本中必须使用$_GET['startDateG']而不是$_POST['startDateG']。否则,您应该使用jQuery.post

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32449684

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档