1

所以我使用的是谷歌图表 API,但是当我使用数据解码传递给 API 的 HTML 实体时,会显示图表并且标题仍然包含未解码的 HTML 实体,并且我看到类似 ‡ 的东西而不是符号它代表 ..

下面是一个例子..我如何确保数据在图表中解码 http://i1283.photobucket.com/albums/a542/semi852/Capture_zps33daa7b6.png

<?php
session_start();
// disable any caching by the browser
header('Expires: Mon, 14 Oct 2002 05:00:00 GMT');              // Date in the past
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT'); // always modified
header('Cache-Control: no-store, no-cache, must-revalidate');  // HTTP 1.1
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');                                    // HTTP 1.0
require_once('../config.php');
require_once '../_includes/auxiliary_functions.php';


?>

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>Charts</title>
            <link rel="stylesheet" title="Style CSS" href="report_assets/style.css" type="text/css" media="all" />
            <link rel="stylesheet" title="Style CSS" href="report_assets/cwcalendar.css" type="text/css" media="all" />
            <link rel="stylesheet" title="Style CSS" href="report_assets/colorbox.css" type="text/css" media="all" />
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <script src="../_js/jquery-1.6.2.min.js" type="text/javascript" charset="utf-8"></script>
            <script src="../_js/timer.js" type="text/javascript" charset="utf-8"></script>
            <script type="text/javascript" src="http://www.google.com/jsapi"></script>

            <?php
            $data =  $_GET['data']; 
            $title = $_GET['title'];
            $data = strip_tags(DecodeSpecialChars(html_entity_decode($data))); 

?>
         <script type="text/javascript">
            function htmlEntities(str) {
    return String(str).replace(/&#135;/g, '‡;');
}
</script>


          <script type="text/javascript">

              google.load('visualization', '1', {packages: ['corechart']});

            //set callback
            google.setOnLoadCallback (createChart);

            //callback function
            function createChart() {

                //create data table object
                var dataTable = new google.visualization.DataTable();


               //create data table object
                var dataTableMulticolumn = new google.visualization.DataTable();


                //define columns for first example
                dataTable.addColumn('string','Question');
                dataTable.addColumn('number', 'Answers');

                //define rows of data for first example
                dataTable.addRows([<?php echo strip_tags(DecodeSpecialChars(html_entity_decode($data))); ?>]);





                //instantiate our chart objects
                var chart = new google.visualization.PieChart (document.getElementById('Chart'));

                //define options for visualization
                 var options = {width: 1550, height: 900,legendFontSize:14,fontSize:25,is3D: true, title: "<?php echo $title; ?>"};

                //draw our chart charts
                chart.draw(dataTable, options);

               //register callbacks
                google.visualization.events.addListener(eventsChart, 'onmouseover', showDetails);
                google.visualization.events.addListener(eventsChart, 'onmouseout', hideDetails);

            }

            function showDetails(e) {
                switch (e['row']) {
                    case 0: document.getElementById('details0').style.visibility='visible';
                        break;
                    case 1: document.getElementById('details1').style.visibility='visible';
                        break;
                    case 2: document.getElementById('details2').style.visibility='visible';
                        break;
                    case 3: document.getElementById('details3').style.visibility='visible';
                        break;
                }
            }


            function hideDetails(e) {
                switch (e['row']) {
                    case 0: document.getElementById('details0').style.visibility='hidden';
                        break;
                    case 1: document.getElementById('details1').style.visibility='hidden';
                        break;
                    case 2: document.getElementById('details2').style.visibility='hidden';
                        break;
                    case 3: document.getElementById('details3').style.visibility='hidden';
                        break;
                }
            }

   </script>

        <?php           

        echo "<div class='charts'>"; 
        echo "<div id='Chart'></div>";
        echo "</div>";
        ?>
4

1 回答 1

0

如果您仍在寻找答案,解决方案是使用 javascript Unicode 字符值(例如\u2021‡),而不是 HTML 代码。

于 2013-07-28T06:38:44.193 回答