2009-05-01 53 views
1

我的問題是無法在.tpl文件中渲染圖表。下面的代碼是從融合圖表文檔檢查採取reference在PHP中使用Fusion Chart並在Smarty模板引擎中渲染

<?php 
    include("../Includes/FusionCharts.php"); 

    //Create an XML data document in a string variable 
    $strXML = ""; 
    $strXML .= "<graph caption='Monthly Unit Sales' xAxisName='Month' yAxisName='Units' 
    decimalPrecision='0' formatNumberScale='0'>"; 
    $strXML .= "<set name='Jan' value='462' color='AFD8F8' />"; 
    $strXML .= "<set name='Feb' value='857' color='F6BD0F' />"; 
    $strXML .= "<set name='Mar' value='671' color='8BBA00' />"; 
    $strXML .= "<set name='Apr' value='494' color='FF8E46' />"; 
    $strXML .= "<set name='May' value='761' color='008E8E' />"; 
    $strXML .= "<set name='Jun' value='960' color='D64646' />"; 
    $strXML .= "<set name='Jul' value='629' color='8E468E' />"; 
    $strXML .= "<set name='Aug' value='622' color='588526' />"; 
    $strXML .= "<set name='Sep' value='376' color='B3AA00' />"; 
    $strXML .= "<set name='Oct' value='494' color='008ED6' />"; 
    $strXML .= "<set name='Nov' value='761' color='9D080D' />"; 
    $strXML .= "<set name='Dec' value='960' color='A186BE' />"; 
    $strXML .= "</graph>"; 

    //Create the chart - Column 3D Chart with data from strXML variable using dataXML method 
    echo renderChartHTML("../../FusionCharts/FCF_Column3D.swf", "", $strXML, "myNext", 600, 300); 
?> 


它的工作原理,如果我在正常.PHP,但如何將renderChartHTML值傳遞給Smarty的第三方物流,這樣它會被顯示在呈現的例子一個<div>{$chartdata}</div>像這樣。如果有任何示例在smarty tpl中顯示Fusion圖表,那麼將會很棒。

到現在爲止,我能夠獲得圖表,如將$ strXML分配給smarty變量並將值直接傳遞給嵌入參數。任何人都會提出一個更好的方法來做到這一點

在PHP:

$smarty->assign('strXML', $strXML); 

在.tpl:

<embed src="FCF_MSLine.swf" flashVars="&dataXML={$strXML}&chartWidth=900&chartHeight=600" quality="high" width="900" height="600" name="testgraph" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> 

回答

2
$output = renderChartHTML("../../FusionCharts/FCF_Column3D.swf", "", $strXML, "myNext", 600, 300); 
$smarty->assign('chartdata', $output);