dsfdsf23423 2019-02-28 15:31
浏览 66

如何使用谷歌图表api生成当前年,月和日期

I want to generate the Year, Month and Day inside the google chart API using the foreach method I'm getting the value for the chart. Please help me to solve this problem. I have attached my code as follows:

    google.charts.load('current', {'packages':['corechart']});
    google.charts.setOnLoadCallback(drawChart);

    function drawChart() {

        var data = new google.visualization.DataTable();
        data.addColumn('date', 'Time of Day');
        data.addColumn('number', 'Users');

        data.addRows([
            [new Date(2019, 2, 1), 5],[new Date(2019, 2, 2), 5],[new Date(2019, 2, 3), 5],[new Date(2019, 2, 4), 5],[new Date(2019, 2, 5), 5]

            <?php
            foreach($TotPosts as $totPos)
            {
                echo "[new Date(2019, 2, 1), ".$totPos->totUser."],";
            }
            ?>

        ]);

        var options = {
            is3D:true,
            title: 'Rate the Day on a Scale of 1 to 10',
            width: 900,
            height: 500,
            hAxis: {
                format: 'd/M/yy',
                gridlines: {count: 15}
            },
            vAxis: {
                gridlines: {color: 'none'},
                minValue: 0
            }
        };

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

        chart.draw(data, options);

        var button = document.getElementById('change');

        button.onclick = function () {

            // If the format option matches, change it to the new option,
            // if not, reset it to the original format.
            options.hAxis.format === 'M/d/yy' ?
                options.hAxis.format = 'MMM dd, yyyy' :
                options.hAxis.format = 'M/d/yy';

            chart.draw(data, options);
        };
    }

Here total user count is coming but I don't know how to generate the Year, Month and Dat here.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测