在php页面加载JpGraph

时间:2015-09-08 05:13:34

标签: php jquery ajax jpgraph

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

的index.php

$('#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

<div id="cont"></div>

Graphs.php

<?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);

?>

1 个答案:

答案 0 :(得分:1)

尝试这样的事情:

$('#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提取数据,因此您必须在$_GET['startDateG']脚本中使用$_POST['startDateG']而不是PHP。否则你应该使用jQuery.post