0

我将融合图表与我的 PHP 和 MySQL 编码一起使用。我可以用数据库数据绘制图表..现在我想添加一个下载按钮来将图表导出为 PDF、png 和 JPG 格式...我找到了融合图表 Javascript 示例 & 我尝试将该代码应用于我的 php 代码并导出图表..但我做不到....只显示图表...她的帮助 JS 代码,我使用...:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <title>My First chart using FusionCharts - Exporting pure JavaScript chart</title>
        <script type="text/javascript" LANGUAGE="Javascript" SRC="../../../Charts/FusionCharts.js"></script>
        <script type="text/javascript" LANGUAGE="Javascript" SRC="../../assets/ui/js/jquery.min.js"></script>
        <script type="text/javascript" LANGUAGE="Javascript" SRC="../../assets/ui/js/lib.js"></script>

        <link href="../../assets/ui/css/style.css" rel="stylesheet" type="text/css" />

        <!--[if IE 6]>
        <script type="text/javascript" src="../assets/ui/js/DD_belatedPNG_0.0.8a-min.js"></script>

<script>
          /* select the element name, css selector, background etc */
          DD_belatedPNG.fix('img');

          /* string argument can be any CSS selector */
        </script>
        <![endif]-->

        <style type="text/css">
            h2.headline {
                font: normal 110%/137.5% "Trebuchet MS", Arial, Helvetica, sans-serif;
                padding: 0;
                margin: 25px 0 25px 0;
                color: #7d7c8b;
                text-align: center;
            }
            p.small {
                font: normal 68.75%/150% Verdana, Geneva, sans-serif;
                color: #919191;
                padding: 0;
                margin: 0 auto;
                width: 664px;
                text-align: center;
            }
        </style>
    </head>
    <body>

        <div id="wrapper">

            <div id="header">


               <div class="logo"><a class="imagelink"  href="http://www.fusioncharts.com/" target="_blank"><img src="../../assets/ui/images/fusionchartsv3.2-logo.png" width="131" height="75" alt="FusionCharts XT logo" /></a></div>
                <h1 class="brand-name">FusionCharts XT</h1>
                <h1 class="logo-text">Exporting pure JavaScript chart</h1>
            </div>

            <div class="content-area">
                <div id="content-area-inner-main">
                    <p class="text" align="center" >Exporting pure JavaScript chart.Click the download button on the top right corner of the chart. </p>
                    <p>&nbsp;</p>

                    <div class="gen-chart-render">
                        <center>
                            <div id="chartContainer">FusionCharts will load here</div>

                            <script type="text/javascript"><!--

                                FusionCharts.setCurrentRenderer('JavaScript');
                                var myChart = new FusionCharts("../../Charts/Column2D.swf", "myChartId", "400", "300", "0", "1");
                                myChart.setXMLData('<chart caption="Weekly Sales Summary" xAxisName="Week" yAxisName="Sales" numberPrefix="$" \n\
                                   exportEnabled="1" >\n\
                                      <set label="Week 1" value="14400" /> \n\
                                      <set label="Week 2" value="19600" /> \n\
                                      <set label="Week 3" value="24000" /> \n\
                                      <set label="Week 4" value="15700" /> \n\
                                </chart>');

                                myChart.render("chartContainer");


                                // -->
                            </script>
                        </center>
                    </div>
                    <div class="clear"></div>
                    <p>&nbsp;</p>
                    <p class="small">    </p>
                    <div class="underline-dull"></div>
                    <div>

                <p class="highlightBlock">The above sample showcases exporting pure JavaScript charts. Click <a href="../../../Contents/index.html?exporting-image/ECPureJS.html" target="_blank">here</a> to know more on how the code of this example works.</p>
            </div>

                </div>
            </div>

            <div id="footer">
                <ul>
                    <li><a href="../index.html"><span>&laquo; Back to list of examples</span></a></li>
                    <li class="pipe">|</li>
                    <li><a href="../../NoChart.html"><span>Unable to see the chart above?</span></a></li>
                </ul>
            </div>
        </div>
    </body>
</html>

要查看此代码的输出,请单击此链接:输出

这是我的 php,mysql 代码:

<?php

include("FusionCharts/FusionCharts.php");
?>
<HTML>
<HEAD>
    <TITLE>
    FusionCharts - Array Example using Single Series Column 3D Chart
    </TITLE>    
    <SCRIPT LANGUAGE="Javascript" SRC="FusionCharts/FusionCharts.js"></SCRIPT>
    <!--<script type="text/javascript" language="JavaScript" src="FusionCharts/FusionChartsExportComponent.js"></script>-->
<script type="text/javascript" LANGUAGE="Javascript" SRC="FusionCharts/jquery.min.js"></script>
<script type="text/javascript" LANGUAGE="Javascript" SRC="FusionCharts/lib.js"></script>
<link href="FusionCharts/style.css" rel="stylesheet" type="text/css" />

    <style type="text/css">
    <!--
    body {
        font-family: Arial, Helvetica, sans-serif;
        font-size: 12px;
    }
    -->
    </style>
</HEAD>
<BODY>

<CENTER>
<h2>FusionCharts Examples</h2>
<h4>Plotting single series chart from data contained in Array.</h4>
<?php
include("db_connect.php");

    $arrData[0][2] = "A";
    //send + char to xml file////
    $arrData[1][3] = str_replace('+', '%2B', 'A+');
    $arrData[2][4] = "A-";
    $arrData[3][5] = "B";
    $arrData[4][6] = str_replace('+', '%2B', 'B+');
    $arrData[5][7] = "B-";
    $arrData[6][8] = "C";
    $arrData[7][9] = str_replace('+', '%2B', 'C+');
    $arrData[8][10] = "C-";
    $arrData[9][11] = "D";
    $arrData[10][12] = str_replace('+', '%2B', 'D+');
    $arrData[11][13] = "E";
    $arrData[12][14] = "AB";
    $arrData[13][15] = "NE";
    $arrData[14][16] = "MC";

    //Store db data
    // Fetch all  records
    $sql = "SELECT grade, COUNT(*) 'No_Of_grades' FROM std_results WHERE course_code ='CSC1113' GROUP BY grade ORDER BY grade ASC";
    $result = mysql_query($sql) or die(mysql_error());
    while($ors = mysql_fetch_array($result)) {
    $grd=$ors['grade'];
    switch ($grd)
{
case "A":
  $arrData[0][17]=$ors['No_Of_grades'];
  break;
case "A+":
  $arrData[1][18]=$ors['No_Of_grades'];
  break;
case "A-":
  $arrData[2][19]=$ors['No_Of_grades'];
  break;
  case "B":
  $arrData[3][20]=$ors['No_Of_grades'];
  break;
  case "B+":
  $arrData[4][21]=$ors['No_Of_grades'];
  break;
  case "B-":
  $arrData[5][22]=$ors['No_Of_grades'];
  break;
 case "C":
  $arrData[6][23]=$ors['No_Of_grades'];
  break;
  case "C+":
  $arrData[7][24]=$ors['No_Of_grades'];
  break;
  case "C-":
  $arrData[8][25]=$ors['No_Of_grades'];
  break;
  case "D":
  $arrData[9][26]=$ors['No_Of_grades'];
  break;
  case "D+":
  $arrData[10][27]=$ors['No_Of_grades'];
  break;
  case "E":
  $arrData[11][28]=$ors['No_Of_grades'];
  break;
  case "AB":
  $arrData[12][29]=$ors['No_Of_grades'];
  break;
  case "NE":
  $arrData[13][30]=$ors['No_Of_grades'];
  break;
default:
  $arrData[14][31]=$ors['No_Of_grades'];
}

    }

    //set vlaue zero for othe grades..
    for($i=0;$i<15;$i++){
        if(!isset($arrData[$i][32])){
            $arrData[$i][33]=0;
            }
        }
    //Now, we need to convert this data into XML. We convert using string concatenation.
    //Initialize <chart> element
    $strXML = "<chart caption='Exam result for CSC113A ' numberPrefix='' formatNumberScale='10' xAxisName='Grades' yAxisName='No Of Students' bgColor='995699,FEEFFF' exportEnabled='1' exportAtClient='0' exportAction='download' exportTargetWindow='_blank'>";
    //Convert data to XML and append
    foreach ($arrData as $arSubData)
        $strXML .= "<set label='" . $arSubData[1] . "' value='" . $arSubData[2] . "' />";

    //Close <chart> element
    $strXML .= "</chart>";

    //Create the chart - Column 3D Chart with data contained in strXML
    echo renderChart("FusionCharts/Column3D.swf", "", $strXML, "Results", 600, 300, false, false);
?>

<BR><BR>

</CENTER>
</BODY>
</HTML>

我的代码输出是:在此处输入图像描述

如何将导出(下载)部分添加到我的 php、mysql 代码并获得以下输出: 在此处输入图像描述

我如何将上面的 Javascript 融合图表导出代码应用到我的 PHP、MySql 代码????需要你的大力帮助朋友..thanxx 这么多....

4

1 回答 1

0
  1. 更新到最新版本的 FusionCharts XT(js、SWF 和 PHP 文件)。这是重要的一步。完成后请清除浏览器缓存。

  2. FC_SetRenderer( "javascript" );在你之前添加echo renderChart("...

  3. 您的 XML 数据应包含exportEnabled='1'

于 2012-12-26T10:06:50.510 回答