Fusionchart不会从数据库mysql中显示

时间:2015-01-31 14:13:21

标签: php mysql fusioncharts

我想知道为什么我的图表不起作用。我在项目中包含了FusionCharts.php和其他必要文件,并使用下面的代码。该页面出现在我的浏览器上,但不是显示图表而是出现No data to dispay错误。可能是什么问题呢?此致

    <?php
    //We've included ../Includes/FusionCharts.php and ../Includes/DBConn.php, which contains

    include("Includes/FusionCharts.php");
    include("Includes/DBConn.php");
    ?>
    <HTML>
    <HEAD>
        <TITLE>
        FusionCharts Free - Database Example
        </TITLE>

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

    <CENTER>
    <h2><a href="http://www.fusioncharts.com" target="_blank">FusionCharts Free</a> -Database and Drill-Down Example</h2>


    <?php
        //In this example, we show how to connect FusionCharts to a database.
    //For the sake of ease, we've used an MySQL databases containing two
    //tables.

    // Connect to the DB
        $link = connectToDB();

// Fetch all factory records

        $strQuery = "select SUM(quantity) AS SUM, YEAR(datePro) AS YEAR FROM factory_output GROUP BY YEAR(datePro ) ";
        $result = mysql_query($strQuery) or die(mysql_error());

    //$strXML = "<graph caption='Factory Output report' subCaption='By Quantity' pieSliceDepth='30' showBorder='1' showNames='1' formatNumberScale='0' numberSuffix=' Units' decimalPrecision='0'>";

        $strXML = "<chart caption='Annual Revenue - last 3 years' numberPrefix='$'>";

        //Iterate through each factory

            while ($ors = mysql_fetch_array($result)){

        //Generate <set name='..' value='..' />  
        $strXML .= "<set label ='" . $ors['YEAR'] . "' value='" . $ors['SUM'] . "' />";
                }
//Finally, close <graph> element

        $strXML .= "</chart>";

//Create the chart - Pie 3D Chart with data from $strXML

    echo renderChart("charts/FCF_Column3D.swf", "", $strXML, "FactorySum", 650, 450);

        mysql_free_result($result);



        mysql_close($link);




    ?>
    <BR><BR>
    <a href='../NoChart.html' target="_blank">Unable to see the chart above?</a>
    <H5 ><a href='../default.htm'>&laquo; Back to list of examples</a></h5>
    </CENTER>
    </BODY>
    </HTML>

1 个答案:

答案 0 :(得分:0)

代码中没有问题,它应该可以正常工作。但是,您是否可以根据呈现的图表生成XML数据并检查返回的XML格式是否正确?

可能出现以下情况,即出现错误消息而不是图表:

  • 您的XML数据不包含FusionCharts XT可以绘制的任何数据。在这种情况下,您的XML只包含图表或数据集标记,它们之间没有任何数据。
  • 您可能正在渲染单系列图表并以多系列格式提供数据,反之亦然。在这种情况下,您将收到“无数据显示”消息。