【问题标题】:Chart.js - rendering a time graph with 'day' as a unit on x-axisChart.js - 在 x 轴上以“天”为单位呈现时间图
【发布时间】:2022-07-08 04:34:00
【问题描述】:

我正在使用 Chart.js (2.7)。我在 ISO 格式的标签数组中有我的日期,我也尝试以毫秒为单位保存它们。而我的数据集的数据是随机正整数。

我的图表配置如下所示:

 {
    type: 'bar',
    data: {
        datasets: [] as any[],
        labels: [] as string[]
    },
    options: {
        legend: {
            display: false
        },
        maintainAspectRatio: false,
        plugins: {
            legend: {
                position: 'top',
            }
        },

        scales: {
            xAxes: [{
                ticks: {
                    autoSkip: true
                },
                scaleLabel: {
                    display: true,
                    labelString: 'Pinged At (Date and Time)'
                },
                type: "time",
                
                time: {
                    unit: 'day',
                    unitStepSize: 1,
                    stepSize: 1
                }
            }],

            yAxes: [{
                scaleLabel: {
                    display: true,
                    labelString: 'Response Time (ms)'
                }
                
            }]
        }
    }
}

这不会渲染任何东西!它确实检测到标签是什么:

但没有数据点。但是,当我将单位设置为小时,然后显示数据时,它工作正常。

我的标签数组包含如下数据点: ["2022-06-30T16:24:07.713+05:00", "2022-07-07T15:23:02.742+05:00"]

我的数据点是这样的: [1,11]

谁能告诉我我的配置是否有错误?

【问题讨论】:

    标签: javascript chart.js


    【解决方案1】:

    如果您要推送数据集,您需要在之后调用 myChart.update()。当我没有得到数据点时,这是我的第一个想法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多