Open flash chart中显示中文

    open flash chart是一个在php中方便制图的工具包,关于open flash chart的使用和下载可以参考http://teethgrinder.co.uk/open-flash-chart/, 我们从2008年年初我们就开始用户open flash chart进行画图,但是一直不知道如何在flash中显示中文,最近open flash chart出了最新的2.0版本,里面提及了当open flash chart的数据文件采用的是UTF-8编码就能正常显示中文,我尝试了一下,确实如此。那么在版本1中修改数据文件的编码方式为UTF-8,然后输入中文,结果在flash中也是能正常显示中文的,唉,一年多一直不知道如何输入中文,原来就是一个编码的问题。

 

   举一个1.0版本的例子:

 

   我在linux下用vim编辑了一下如下文件,选择使用utf-8编码,然后将文件保存成pic.php,并从linux下拷贝出来,放到我们的windows服务器上,注意,中文部分在正常的文本编辑工具下显示的是乱码哦。

 

    <?php

include_once( './ofc-library/open-flash-chart.php' );
$servername = 'XXX';
$username = 'xxxx';
$password = 'xxxxsss';
$dbname = 'ssss';

$conn = mssql_connect($servername,$username,$password) or die("couldn't open SQL Server $servername <br>");
$db = mssql_select_db($dbname,$conn) or die("couldn't open database $dbname <br>");


if( isset($_GET["enddate"]) && $_GET["enddate"]!="")
{
    $enddate=$_GET['enddate'];
}

if( isset($_GET["startdate"]) && $_GET["startdate"]!="" && $_GET["startdate"]<$enddate)
{
    $startdate=$_GET['startdate'];
}
else {
    $startdate = $enddate;
}

    $query = "select  convert(varchar,a.thedate,112) as thedate,
                                pv,
                                uv
                        from  rpt_aa_daily

                        where thedate between '$startdate' and '$enddate'

                       order by thedate";
$result = mssql_query($query);


$thex0=array();
$pv=array();
$uv=array();
$MaxY1=0;
$MaxY2=0;

while($row = mssql_fetch_array($result))
{
    array_push($thex0,$row["thedate"]);
    array_push($pv,$row["pv"]);
    array_push($uv,$row["uv"]);
}

$MaxY1 = max($pv);
$MaxY1 = 11*intval(round($MaxY1/10))+10;
$MaxY2 = max($uv);
$MaxY2 = 11*intval(round($MaxY2/10))+10;

$g = new graph();
$g->title( '鎵€鏈夋父鎴忕殑鐐瑰嚮閲?,'{font-size: 18px; color: #800000}' );

$g->set_x_labels($thex0 );
$g->set_x_label_style( 10, '0x000000', 2, 2 );

$g->set_data($pv);
$g->line_dot(3, 5, '0xFF00CC', 'PV', 10);

$g->set_data($uv);
$g->line_dot(3, 5, '0x00AACC', 'UV', 10);

$g->set_tool_tip( '#key#<br>date:#x_label#<br>#val#<br>' );

$g->attach_to_y_right_axis(2);

$g->set_y_right_max($MaxY2);
$g->set_y_right_min(min($uv)-100);

$g->set_y_min(min($pv)-100);
$g->set_y_max($MaxY1 );
$g->y_label_steps( 5 );
echo $g->render();

?>

 

然后写一个调用这个数据文件的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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>游戏点击量</title>
<style type="text/css">
#bowser{
        width:2000px
        margin:2px auto;
        border-collapse:collapse;
        font-family:arial;
        font-size:12px;
        text-align:center;
}
.segments{clear:both; text-align:center;margin:auto;}
.inner_segments{ position:relative;clear:both;margin:0 auto; width:800px;}

#my_chart1{float:left; margin-right:3px;}
#my_chart2{float:left; margin-left:3px;}
</style>
</head>
<body>
 <H2 align="center"><font color="#330099">游戏点击量</font></H2>
<?php
if( isset($_POST["enddate"]) && $_POST["enddate"]!="")
{
    $enddate=$_POST['enddate'];
}
else {
    $enddate = date("Ymd",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
    }
   
if( isset($_GET["enddate"]) && $_GET["enddate"]!="")
{
    $enddate=$_GET['enddate'];
}


if( isset($_POST["startdate"]) && $_POST["startdate"]!="" && $_POST["startdate"]<$enddate)
{
    $startdate=$_POST['startdate'];
}
else {
    $startdate = $enddate;
}
?>

<div class="segments">
<div class="inner_segments">
<div id="my_chart1">
<?php
include_once('../../../../../ofc-library/open_flash_chart_object.php');
open_flash_chart_object( 397, 220, 'http://'. $_SERVER['SERVER_NAME'] .':'.$_SERVER['SERVER_PORT'].'/Pic.php?enddate='.$enddate.'&startdate='.$startdate,false);
?>
</div><!--end of my_chart1-->
<div id="my_chart2">
<?php
include_once('../../../../../ofc-library/open_flash_chart_object.php');
open_flash_chart_object( 397, 220, 'http://'. $_SERVER['SERVER_NAME'] .':'.$_SERVER['SERVER_PORT'].'/Pic.php?enddate='.$enddate.'&startdate='.$startdate,false);
?>
</div><!--end of my_chart2-->
</div><!--end of inner_segments-->
</div><!--end of segments-->
<p>
<p>
<div class="segments">
<div class="inner_segments">
<form  id="checkdate" method="POST" action="<?php echo $PHP_SELF ?>" target="_self">
            起始日期:<input type="text" name="startdate" value="<?php echo $startdate;?>">
            结束日期:<input type="text" name="enddate" value="<?php echo $enddate;?>">
                     <input type=submit value="查询">
</form>
<form  id="spool" method="POST" action="./spool.php" target="_self">       
            <input type="hidden" name="spool_startdate" value="<?php echo $startdate;?>">
            <input type="hidden" name="spool_enddate" value="<?php echo $enddate;?>">
              <input type="submit" value="导出">
</form>
</div><!--end of inner_segments-->
</div><!--end of segments-->

</body>
</html>

你可能感兴趣的:(Open flash chart中显示中文)