raphael-min.js:10错误: 属性d:预期数字,“M,0,0”

问题描述 投票:0回答:1

我无法在morris js中绘制线图。下面是我的javascript代码,用于从datebase中检索数据,并在我的控制台日志中遇到此错误“raphael-min.js:10错误:属性d:预期数字,”M,0,0“。”

    <script>
var balance = '<?php $connection = Yii::$app->getDb();$command = 
  $connection->createCommand("select count(*) as tally from 
 tbmessages_external where  field3='310000' and
 (datex>=TO_DATE(to_char('21-02-18 15:00:00'), 'dd-mm-yy hh24:mi:ss')  
   and datex<=TO_DATE(to_char('21-02-18 17:59:59'), 'dd-mm-yy 
   hh24:mi:ss'))");
    serialize($command);?>';


console.log(balance);
var line = new Morris.Line({
    element: 'bi-chart',
    resize: true,
    data: [
        { hours: '00:00', a: balance},
        { hours: '01:00', a: balance},
        { hours: '02:00', a: balance},
        { hours: '03:00', a: balance},
        { hours: '04:00', a: balance},
        { hours: '05:00', a: balance},
        { hours: '06:00', a: balance},
        { hours: '07:00', a: balance},
        { hours: '08:00', a: balance},
        { hours: '09:00', a: balance},
        { hours: '10:00', a: balance},
        { hours: '11:00', a: balance},
        { hours: '12:00', a: balance},
        { hours: '13:00', a: balance},
        { hours: '14:00', a: balance},
        { hours: '15:00', a: balance},
        { hours: '16:00', a: balance},
        { hours: '17:00', a: balance},
        { hours: '18:00', a: balance},
        { hours: '19:00', a: balance},
        { hours: '20:00', a: balance},
        { hours: '21:00', a: balance},
        { hours: '22:00', a: balance},
        { hours: '23:00', a: balance},
    ],
    //data:balance,
    xkey: 'hours',
    ykeys: ['a'],
    labels: ['BI'],
    lineColors: ['#3c8dbc'],
    hideHover: 'auto',
    parseTime: false

});

javascript php yii2 linechart morris.js
1个回答
0
投票

在你的PHP代码中你只是准备一个sql命令但不执行你应该添加 - > queryScalar();用于反转Count(*)数据(标量是第一行的第一列)

<script>
  var balance = <?php  $connection = Yii::$app->getDb();
      $command = $connection->createCommand(
            "select count(*) as tally 
            from tbmessages_external 
            where  field3='310000' 
            and (datex >= TO_DATE(to_char('21-02-18 15:00:00'), 'dd-mm-yy hh24:mi:ss')  
                    and datex<=TO_DATE(to_char('21-02-18 17:59:59'),
                           'dd-mm-yy hh24:mi:ss'))")->queryScalar();;
   echo $command . ';' ;

   ?>';
© www.soinside.com 2019 - 2024. All rights reserved.