【问题标题】:load JpGraph in php page在 php 页面中加载 JpGraph
【发布时间】:2015-12-03 15:49:56
【问题描述】:

我想使用ajaxjavascript 在另一个php 页面中加载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>

更新:

//这是我要加载图片的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);

?>

【问题讨论】:

    标签: php jquery ajax jpgraph


    【解决方案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 获取数据,所以您必须在PHP 脚​​本中使用$_GET['startDateG'] 而不是$_POST['startDateG']。否则你应该使用jQuery.post

    【讨论】:

    • 它不显示图像它的显示数据如下::PNG IHDR...it. IDATx...y\SW.8.'.F.K٭.V...j; tt�:u������}�.3S_g�kgF���NW�jw;v�kmm�P���V0aQ0 I�����p�$!��>��|�� �s����P|���si�@B!�Bc�j!�B!ty�#�B!4`
    • #cont 是您的ìmg 标签吗?我在您问题的HTML 代码中找不到它。
    • 已解决:我在 Graphs.php 中使用了 img 标签并将其加载到 div 中。
    • 感谢您的帮助。我做的错误不是加载图像而是加载字符串
    猜你喜欢
    • 2017-01-03
    • 2012-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-04
    • 2014-08-09
    • 1970-01-01
    • 2016-03-13
    相关资源
    最近更新 更多