首页 > 解决方案 > 我如何在chartjs图表上显示我的自定义(日-月-年时:分:秒)时间格式?

问题描述

我想在chartjs图表上显示我的自定义(日-月-年小时:分钟:秒->例如:01-05-2019 14:06:47 PM)时间格式
我如何在图表xAxis日期格式上显示这样>>
Day-Month-Year Hour:Min:Sec -->ex: 01-05-2019 14:06:47 PM
时间格式是timeFormat = 'DD/MM/YYYY h:mm:ss a'但在图表上仅显示月、日、年

这是我下面的代码,并且:
在线代码在 >>> https://codepen.io/sibche2013/pen/XQWWbb

var timeFormat = 'DD/MM/YYYY h:mm:ss a';

    var config = {
        type:    'line',
        data:    {
            datasets: [

                {
                    label: "UK Dates",
                    data:  [{
                        x: "01-04-2014 02:15:50", y: 175
                    }, {
                        x: "12-04-2014 12:19:27", y: 177
                    }, {
                        x: "23-04-2014 22:25:47", y: 178
                    }, {
                        x: "28-04-2014 14:46:40", y: 182
                    }],
                    fill:  false,
                    borderColor: 'blue'
                }
            ]
        },
        options: {
            responsive: true,
            title:      {
                display: true,
                text:    "Chart.js Time Scale"
            },
            scales:     {
                xAxes: [{
                    type:       "time",
                    time:       {
                        format: timeFormat,
                        tooltipFormat: 'll'
                    },
                    scaleLabel: {
                        display:     true,
                        labelString: 'Date'
                    }
                }],
                yAxes: [{
                    scaleLabel: {
                        display:     true,
                        labelString: 'value'
                    }
                }]
            }
        }
    };

    window.onload = function () {
        var ctx       = document.getElementById("canvas").getContext("2d");
        window.myLine = new Chart(ctx, config);
    };

标签: datetimechartschart.jsdatetime-format

解决方案


推荐阅读