Apply Javascript fusion chart exporting code to PHP,MySql code

▼魔方 西西 提交于 2019-12-23 05:45:13

问题


i'm using fusion charts with my PHP & MySQL codings . I can draw charts with Database data..Now I want add a download button to export charts as PDF,png & JPG formats...i have found fusion charts Javascript example & I tried to apply that code to my php code & get exporting charts..But I couldn't do it....Only chart displayed...Her the help JS code which I used...:

<!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>

To see the out put of this code click this link :out put

here is my php,mysql code :

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

out put of my code is :

How can I add exporting (downloading) part to my php,mysql code and get following out put :

How can I Apply above Javascript fusion chart exporting code to my PHP,MySql code????Need ur great help friends..thanxx so much....


回答1:


  1. Update to the latest version of FusionCharts XT( js, SWF and PHP files) . This is an important step. Please clear browser cache once done.

  2. Add FC_SetRenderer( "javascript" ); before your echo renderChart("...

  3. Your XML data should contain exportEnabled='1'



来源:https://stackoverflow.com/questions/14035517/apply-javascript-fusion-chart-exporting-code-to-php-mysql-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!