简体   繁体   English

如何将表中的所有值转换为Codeigniter中的图表值

[英]how to get all the values in table to chart values in codeigniter

am using the following code. 我正在使用以下代码。 am getting only the first value and it has been displaying in table. 我只获得第一个值,并且一直在表中显示。 how to get all the values and display in chart. 如何获取所有值并显示在图表中。 though am using for loop am getting only one value. 虽然使用for循环只获得一个值。 can someone give some suggestion how to proceed thanks. 有人可以给一些建议如何进行感谢。

var chart;

var chartData = <?php
        for($i=0;$i<count($six_year);$i++) {

         ?>[{
    year: "<?php echo $six_year[$i]['year']; ?>",
    visits: <?php echo $six_year[$i]['total']; ?>
    }
    ];
<?php

 }
             ?>

Try this, 尝试这个,

<?php
    $chartData=array();
    for($i=0;$i<count($six_year);$i++) {
        $chartData[]=array('year'=>$six_year[$i]['year'],'visits'=>(int)$six_year[$i]['total']);
    }
    $chartData=json_encode($chartData);
?>
<script>
    var chart;
    var chartData ='<?php echo $chartData;?>';
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM