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 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题