duan246558 2019-06-04 10:18
浏览 79

mysql查询谷歌图表中的日期格式

Give date format a mysql data query to create google chart with haxis date.

Error : Type mismatch. Value 2019-05-25 does not match type date in column index 0.

The data of the query is 2019-05-25 and a number , the problem is the format of the date that don't accept it by the google chart.

Any idea?

<html>
 <head>
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi" > </script>
 </head>  
 <body>
   <div id="line_chart" style="width: 100%; height: 500px"></div>
<?php

    $consulta = "SELECT fecha as dia,SUM(importe) as importe 
                FROM tfg.reservas 
                WHERE fecha  < '2019-05-31' 
                AND fecha > '2019-05-20' 
                GROUP BY DAY(fecha) asc;";

    $json = array();   
    $resultado = mysqli_query($conexion,$consulta);
    if ($resultado->num_rows > 0) {
        while($fila = mysqli_fetch_array($resultado)) {
            $dataRow = array(
                      $fila['dia'],
                      $fila['importe'],

                  );
            array_push($json, $dataRow);
        }
    }

    $jsonstring = json_encode($json);
?>
<script type="text/javascript">

google.charts.load('current', {packages: ['corechart', 'line']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
    var data = google.visualization.arrayToDataTable([
        [{type: 'date', label: 'dia'}, {type: 'number', label: 'importe'}]
        ]);

    data.addRows(<?= $jsonstring ?>);

    var options = {
              title: 'Importe en el Último Mes',
              width: 900,
              height: 500,
              hAxis: {
                format: 'yyyy-M-d'
              },
              vAxis: {
                gridlines: {color: 'none'},
                minValue: 0
              }
        };

    var chart = new google.visualization.LineChart(document.getElementById('line_chart'));

    chart.draw(data, options);
}
</script>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么