yii框架结合charjs实现统计30天数据的方法(2)

js

// 按天获取订单数量
  var dayOrderCountChartCanvas = $('#dayOrderCountChart').get(0).getContext('2d')
  var dayOrderCountChartData = {
   labels : <?= json_encode($dayOrderChar['labels'], true) ?>,
   datasets: [
    {
     label        : '<?= $dayOrderChar['orderCountLabel'] ?>',
     backgroundColor   : 'rgba(0, 192, 293, 0.5)',
     data        : <?= json_encode($dayOrderChar['orderCounts'], true) ?>
    }
   ]
  }
 
  var dayOrderCountChartOptions = {
    scales: {
      xAxes: [{
        gridLines: {
          display: false
        }
      }],
      yAxes: [{
        gridLines: {
          display: false
        }
      }]
    }
  }
 
  var dayOrderCountChart = new Chart(dayOrderCountChartCanvas, {
    type: 'line',
    data: dayOrderCountChartData,
    options: dayOrderCountChartOptions
  });
 
  // 按天获取订单及金额
  var dayOrderAmounCanvas = $('#dayOrderAmountChart').get(0).getContext('2d')
  var dayOrderAmounData = {
   labels : <?= json_encode($dayOrderChar['labels'], true) ?>,
   datasets: [
    {
     label        : '<?= $dayOrderChar['orderAmountLabel'] ?>',
     backgroundColor   : 'rgba(0, 192, 293, 0.5)',
     data        : <?= json_encode($dayOrderChar['orderAmounts'], true) ?>
    },
    {
     label        : '<?= $dayOrderChar['orderPayAmountLabel'] ?>',
     backgroundColor   : 'rgba(0, 166, 90, 0.5)',
     data        : <?= json_encode($dayOrderChar['orderPayAmounts'], true) ?>
    }
   ]
  }
 
  var dayOrderAmounOptions = {
    scales: {
      xAxes: [{
        gridLines: {
          display: false
        }
      }],
      yAxes: [{
        gridLines: {
          display: false
        }
      }]
    }
  }
 
  var dayOrderAmountChart = new Chart(dayOrderAmounCanvas, {
    type: 'line',
    data: dayOrderAmounData,
    options: dayOrderAmounOptions
  });

记住,yii的as一定要在模型利定义公用变量

public $char_time; // 按时间统计
  public $total_order; // 所有订单
  public $total_order_amount; // 所有订单总额
  public $total_pay_order; // 支付订单
  public $total_pay_amount; // 支付订单总额
  public $total_order_pay_amount; // 支付总额

更多关于Yii相关内容感兴趣的读者可查看本站专题:《Yii框架入门及常用技巧总结》、《php优秀开发框架总结》、《smarty模板入门基础教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。