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

时间:2018-02-28 17:58:57

标签: javascript php yii2 linechart morris.js

我无法在morris js中绘制折线图。下面是我从日期库中检索数据的javascript代码,并在我的控制台日志中遇到此错误“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

});

1 个答案:

答案 0 :(得分:0)

在你的php代码中,你只需准备一个sql命令但不执行你应该添加 - &gt; 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 . ';' ;

   ?>';