菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
486
0

chartjs

原创
05/13 14:22
阅读数 89674
  1. 官网
    https://www.chartjs.org/docs/latest/axes/cartesian/time.html

  2. 方式1

   if ($('#runExport').length) {
        $.ajax({
        url: '/report/reportInfo/',
        method: 'get',
        }).success(function (data, textStatus, jqXHR) {
            // 每次运行报表
            var ctx = document.getElementById("runExport");
            var ctx1 = document.getElementById("bug_qushi");
            var labels = [];
            var datasetsPass = [];
            var datasetsFaild = [];
            var datasetsSum= [];
            for (var i=0; i<data.length; i++) {
                labels.push(data[i].case_date);
                datasetsPass.push(data[i].case_pass_sum);
                datasetsFaild.push(data[i].case_fail_sum);
                datasetsSum.push(data[i].case_sum);
            }
            var runExport = new Chart(ctx, {
                type: 'bar',
                data: {
                    labels: labels,
                    datasets: [{
                        label: '# 总数',
                        backgroundColor: "#6a4a38",
                        data: datasetsSum
                    }, {
                        label: '# 成功',
                        backgroundColor: "#26B99A",
                        data: datasetsPass
                    }, {
                        label: '# 失败',
                        backgroundColor: "#f33333",
                        data: datasetsFaild
                    }]
                },

                options: {
                    scales: {
                        yAxes: [{
                            ticks: {
                                beginAtZero: true
                            }
                        }]
                    }
                }
            });

        var bug_qushi = new Chart(ctx1, {
            type: 'line',
            data: {
                labels: labels,
                datasets: [
                // {
                //     label: "pass",
                //     backgroundColor: "rgba(38, 185, 154, 0.31)",
                //     borderColor: "rgba(38, 185, 154, 0.7)",
                //     pointBorderColor: "rgba(38, 185, 154, 0.7)",
                //     pointBackgroundColor: "rgba(38, 185, 154, 0.7)",
                //     pointHoverBackgroundColor: "#fff",
                //     pointHoverBorderColor: "rgba(220,220,220,1)",
                //     pointBorderWidth: 1,
                //     data: datasetsPass
                // },
                    {
                    label: "fail",
                    backgroundColor: "rgba(3, 88, 106, 0.3)",
                    borderColor: "rgba(3, 88, 106, 0.70)",
                    pointBorderColor: "rgba(3, 88, 106, 0.70)",
                    pointBackgroundColor: "rgba(3, 88, 106, 0.70)",
                    pointHoverBackgroundColor: "#fff",
                    pointHoverBorderColor: "rgba(151,187,205,1)",
                    pointBorderWidth: 1,
                    data: datasetsFaild
                }]
            },
        });


        }).error(function (jqXHR, textStatus, errorThrown) {
            console.log(jqXHR)
        });


    }
  1. 方式2
   if ($('#bug_qushi').length) {

        var ctx = document.getElementById("bug_qushi");
        var bug_qushi = new Chart(ctx, {
            type: 'line',
            data: {
                labels: ["January", "February", "March", "April", "May", "June", "July"],
                datasets: [{
                    label: "My First dataset",
                    backgroundColor: "rgba(38, 185, 154, 0.31)",
                    borderColor: "rgba(38, 185, 154, 0.7)",
                    pointBorderColor: "rgba(38, 185, 154, 0.7)",
                    pointBackgroundColor: "rgba(38, 185, 154, 0.7)",
                    pointHoverBackgroundColor: "#fff",
                    pointHoverBorderColor: "rgba(220,220,220,1)",
                    pointBorderWidth: 1,
                    data: [31, 74, 6, 39, 20, 85, 7]
                }, {
                    label: "My Second dataset",
                    backgroundColor: "rgba(3, 88, 106, 0.3)",
                    borderColor: "rgba(3, 88, 106, 0.70)",
                    pointBorderColor: "rgba(3, 88, 106, 0.70)",
                    pointBackgroundColor: "rgba(3, 88, 106, 0.70)",
                    pointHoverBackgroundColor: "#fff",
                    pointHoverBorderColor: "rgba(151,187,205,1)",
                    pointBorderWidth: 1,
                    data: [82, 23, 66, 9, 99, 4, 2]
                }]
            },
        });

    }

发表评论

0/200
486 点赞
0 评论
收藏
为你推荐 换一批