我正在尝试使用 PHP 将 JS 脚本写入我的 html 源文档。我已经调查了许多其他论坛,但仍然无法完全确定错误..
我试图嵌入的 JS 脚本遵循默认 YUI 图表库脚本中的语法。
假设我的 php 字符串输出(从echo: $data->dump_yui($row_numbers=false, $col_letters=false, $sheet=0, $table_class='excel');生成)适合参数 r'qd YUI 脚本语法,在我的 html 文档中嵌入脚本时哪里出错了?
PHP 在 HTML 中写入 JavaScript:
<?php
echo "<script language=javascript>";
echo 'document.write("YUI().use('charts',function(Y){var myDataValues = [';
echo $data->dump_yui($row_numbers=false, $col_letters=false, $sheet=0, $table_class='excel');
echo "<br>];<br><br>var styleDef = {series:<br>{Stock:{line:{color:'#898DD5'},marker:{fill:{color:'#eee',alpha:0,wmode:'transparent'},border:{color:'#222',alpha:0,wmode:'transparent'},over:{fill:{color:'#eee'},border:{color:'#000'},width:9,height:9}}},<br>Liability:{line:{color:'#171944'},marker:{fill:{color:'#eee',alpha:0,wmode:'transparent'},border:{color:'#222',alpha:0,wmode:'transparent'},over:{fill:{color:'#eee'},border:{color:'#000'},width:9,height:9}}},<br>Shipment:{line:{color:'#ff0000',alpha:0,wmode:'transparent'},marker:{fill:{color:'#eee',alpha:0,wmode:'transparent'},border:{color:'#ff0000',alpha:0,wmode:'transparent'},over:{fill:{color:'#ff0000',alpha:0,wmode:'transparent'},border:{color:'#000',alpha:0,wmode:'transparent'},width:16,height:16}}},<br>Production:{line:{color:'#FFD700',alpha:0,wmode:'transparent'},marker:{fill:{color:'#eee',alpha:0,wmode:'transparent'},border:{color:'#FFD700',alpha:0,wmode:'transparent'},over:{fill:{color:'#FFD700',alpha:0,wmode:'transparent'},border:{color:'#000',alpha:0,wmode:'transparent'},width:16,height:16}}},<br>Order:{line:{color:'#006400',alpha:0,wmode:'transparent'},marker:{fill:{color:'#eee',alpha:0,wmode:'transparent'},border:{color:'#006400',alpha:0,wmode:'transparent'},over:{fill:{color:'#006400',alpha:0,wmode:'transparent'},border:{color:'#000',alpha:0,wmode:'transparent'},width:16,height:16}}}}};<br>var myAxes={dateRange:{keys:['date'],position:'bottom',type:'category',title:'Date Range',styles:{majorTicks:{display:'none'},label:{rotation:-45,margin:{top:5}},title:{fontSize:'90%'}}}};var mychart=new Y.Chart({dataProvider:myDataValues,interactionType:'planar',render:'#mychart',categoryKey:'Date',styles:styleDef,categoryType:'time',horizontalGridlines:{styles:{line:{color:'#fff'}}},verticalGridlines:{styles:{line:{color:'#fff'}}}});<br>});";
echo '");';
echo "</script>";
?>
(我也尝试过执行不包含“document.write”的脚本)
我对 PHP 相当陌生.. 有什么想法吗?
_ __ 更新(12 年 7 月 18 日):感谢您的反馈 - 我尝试了所有修复程序,但图表仍未呈现,代码:
<?php
echo "<script type='text/javascript'>";
echo 'document.write("YUI().use(\'charts\',function(Y){var myDataValues = [';
echo $data->dump_yui($row_numbers=false, $col_letters=false, $sheet=0, $table_class='excel');
echo "\n];\n\nvar styleDef = {series:\n{Stock:{line:{color:'#898DD5'},marker:{fill:{color:'#eee',alpha:0,wmode:'transparent'},border:{color:'#222',alpha:0,wmode:'transparent'},over:{fill:{color:'#eee'},border:{color:'#000'},width:9,height:9}}},<br>Liability:{line:{color:'#171944'},marker:{fill:{color:'#eee',alpha:0,wmode:'transparent'},border:{color:'#222',alpha:0,wmode:'transparent'},over:{fill:{color:'#eee'},border:{color:'#000'},width:9,height:9}}},<br>Shipment:{line:{color:'#ff0000',alpha:0,wmode:'transparent'},marker:{fill:{color:'#eee',alpha:0,wmode:'transparent'},border:{color:'#ff0000',alpha:0,wmode:'transparent'},over:{fill:{color:'#ff0000',alpha:0,wmode:'transparent'},border:{color:'#000',alpha:0,wmode:'transparent'},width:16,height:16}}},<br>Production:{line:{color:'#FFD700',alpha:0,wmode:'transparent'},marker:{fill:{color:'#eee',alpha:0,wmode:'transparent'},border:{color:'#FFD700',alpha:0,wmode:'transparent'},over:{fill:{color:'#FFD700',alpha:0,wmode:'transparent'},border:{color:'#000',alpha:0,wmode:'transparent'},width:16,height:16}}},<br>Order:{line:{color:'#006400',alpha:0,wmode:'transparent'},marker:{fill:{color:'#eee',alpha:0,wmode:'transparent'},border:{color:'#006400',alpha:0,wmode:'transparent'},over:{fill:{color:'#006400',alpha:0,wmode:'transparent'},border:{color:'#000',alpha:0,wmode:'transparent'},width:16,height:16}}}}};<br>var myAxes={dateRange:{keys:['date'],position:'bottom',type:'category',title:'Date Range',styles:{majorTicks:{display:'none'},label:{rotation:-45,margin:{top:5}},title:{fontSize:'90%'}}}};var mychart=new Y.Chart({dataProvider:myDataValues,interactionType:'planar',render:'#mychart',categoryKey:'Date',styles:styleDef,categoryType:'time',horizontalGridlines:{styles:{line:{color:'#fff'}}},verticalGridlines:{styles:{line:{color:'#fff'}}}});<br>});";
echo '");';
echo "</script>";
?>
** _ 更新(12 年 7 月 20 日):
感谢大家的额外反馈。我将一个页面推送到我的服务器,其中包含三个代码片段(以某种有组织的方式)。
......仍然无法解决这个错误!