Php javascript中的Smarty循环

Php javascript中的Smarty循环,php,jquery,smarty,Php,Jquery,Smarty,我是smarty的新手我想在图表上显示一个数据循环我的代码图表如下所示,例如,只有一条记录的数据,我想在数组中显示它。下面提到的数组和数组的位置在smartytypearray中,因此我将如何将其与jquery集成以用于我的图表 <script type="text/javascript"> window.onload = function () { var chart = new CanvasJS.Chart("chartContainer",

我是
smarty的新手
我想在图表上显示一个数据循环我的代码图表如下所示,例如,只有一条记录的数据,我想在
数组中显示它。下面提到的数组和数组的位置在
smarty
type
array
中,因此我将如何将其与
jquery
集成以用于我的图表

<script type="text/javascript">
    window.onload = function () {
        var chart = new CanvasJS.Chart("chartContainer",
        {
        title:{
                text: "Simple Chart",
                fontSize: 30
            },
            animationEnabled: true,
            axisX:{ gridColor: "Silver",
                tickColor: "silver",
                valueFormatString: "DD/MMM"

            },toolTip:{shared:true},
            theme: "theme2",
            axisY: {
                gridColor: "Silver",
                tickColor: "silver"
            },legend:{
                verticalAlign: "center",
                horizontalAlign: "right"
            },data: [ /* want iteration for loop as smarty array */
            {type: "line",
                showInLegend: true,
                lineThickness: 2,
                name: "Visits",
                markerType: "square",
                color: "#F08080",
                dataPoints: [
                { x: new Date(2010,0,3), y: 650 },
                { x: new Date(2010,0,5), y: 700 },
                { x: new Date(2010,0,7), y: 710 },
                { x: new Date(2010,0,9), y: 658 },
                { x: new Date(2010,0,11), y: 734 },
                { x: new Date(2010,0,13), y: 963 },
                { x: new Date(2010,0,15), y: 847 },
                { x: new Date(2010,0,17), y: 853 },
                { x: new Date(2010,0,19), y: 869 },
                { x: new Date(2010,0,21), y: 943 },
                { x: new Date(2010,0,23), y: 970 }
                ]
            } /* loop will end here */
            ],
          legend:{
            cursor:"pointer",
            itemclick:function(e){
              if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
                e.dataSeries.visible = false;
              }
              else{
                e.dataSeries.visible = true;
              }
              chart.render();
            }
          }
        });
      chart.render();
    }
</script>

window.onload=函数(){
var chart=new CanvasJS.chart(“chartContainer”,
{
标题:{
文字:“简单图表”,
尺寸:30
},
animationEnabled:没错,
axisX:{gridColor:“银色”,
颜色:“银色”,
valueFormatString:“DD/MMM”
},工具提示:{shared:true},
主题:“主题2”,
axisY:{
网格颜色:“银色”,
颜色:“银色”
},图例:{
垂直排列:“中心”,
水平对齐:“右”
},数据:[/*希望循环作为smarty数组进行迭代*/
{类型:“行”,
showInLegend:是的,
线宽:2,
名称:“访问”,
markerType:“方形”,
颜色:“F08080”,
数据点:[
{x:新日期(2010,0,3),y:650},
{x:新日期(2010,0,5),y:700},
{x:新日期(2010,0,7),y:710},
{x:新日期(2010,0,9),y:658},
{x:新日期(2010,0,11),y:734},
{x:新日期(2010,0,13),y:963},
{x:新日期(2010,0,15),y:847},
{x:新日期(2010,0,17),y:853},
{x:新日期(2010,0,19),y:869},
{x:新日期(2010,0,21),y:943},
{x:新日期(2010,0,23),y:970}
]
}/*循环将在此结束*/
],
图例:{
光标:“指针”,
项目点击:功能(e){
if(typeof(e.dataSeries.visible)==“undefined”| | e.dataSeries.visible){
e、 dataSeries.visible=false;
}
否则{
e、 dataSeries.visible=true;
}
chart.render();
}
}
});
chart.render();
}

我想要一个数组循环,用于上面提到的代码中的数据

我想你应该参考这个数组中的数据?我更喜欢你用php创建如下数组:$data=['x'=>'newdate(2010,0,3)','y'=>140],'x'=>'newdate(2010,0,3),'y'=>140]],在javascript中只使用json编码($data);这是编写json DataThank@PankajMakwana最合适的方式