dou91808 2019-06-18 14:19
浏览 57
已采纳

chartJS或/和php print_r不能一起工作

So, i want to input data for the bar chart from a database, i got everything figured out, but something does not work...

Here's a part of the view file,

    var barChartData = {
      labels  : {{print_r($action_names, true)}} ,
      datasets: [
        {
          label               : 'Electronics',
          fillColor           : 'rgba(2, 24, 222, 1)',
          strokeColor         : 'rgba(2, 24, 222, 1)',
          pointColor          : 'rgba(2, 24, 222, 1)',
          pointStrokeColor    : '#c1c7d1',
          pointHighlightFill  : '#fff',
          pointHighlightStroke: 'rgba(2, 24, 222, 1)',
          data                : {{print_r($action_count,true)}}
        }
      ]
    }

this does not work, it displays a blank chart.

The output from {{print_r($action_names, true)}} is ["OBJECT1","OBJECT1","OBJECT3"]

and the output of {{print_r($action_names, true)}} is [1,2,3]

in the exact same formatting, now, if i just post the values in, as text, it works, the chart appears just fine, but when i use the variable, nothing - blank. I need to use the variable, because the database from which i fetch the data, is gonna change quite frequently.

  • 写回答

4条回答 默认 最新

  • drwn65609 2019-06-20 05:28
    关注

    You can simply use implode() function to print your array data,

     labels : [ 
           {{implode(",", $action_names)}}
        ]
    

    &

     data : [
          {{implode(",", $action_count)}}
        ]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备