reactjs - 无法在 React 顶点图表中将时间戳转换为小时分钟和秒
问题描述
我正在使用反应顶点图表来创建一个图表,该图表将显示每个代理的平均响应时间。
我已经设法以时间戳格式获得结果,但我无法将其转换为小时、分钟和秒以在 yaxis 中显示,我已经检查了文档文档链接,但他们只提供了日期时间的示例。这是我使用下面的组件得到的结果
import React, { useState } from 'react';
import Chart from 'react-apexcharts';
const AvgResponseTimeChart = (props) => {
const { prod_data } = props;
const [ data, setData ] = useState([
{
x: 'Agent one',
y: 1589670005
},
{
x: 'Agent one',
y: 1589670307
}
]);
const [ series, setSeries ] = useState([ { data } ]);
const [ options, setOptions ] = useState({
chart: {
type: 'bar',
height: 350
},
plotOptions: {
bar: {
horizontal: false,
columnWidth: '25%',
endingShape: 'rounded'
}
},
dataLabels: {
enabled: false
},
stroke: {
show: true,
width: 2,
colors: [ 'transparent' ]
},
xaxis: {
type: 'category'
},
yaxis: {
labels: {
datetimeFormatter: {
formatter: function(value, timestamp) {
return new Date(timestamp).toLocaleTimeString();
}
}
}
},
fill: {
opacity: 1
},
tooltip: {
y: {
formatter: function(value, timestamp) {
return new Date(timestamp);
}
}
}
});
return (
<div id="chart">
<Chart options={options} series={series} type="bar" height={350} />
</div>
);
};
export default AvgResponseTimeChart;
我已经搜索了类似的问题但没有成功,如果有人可以帮助我,我将非常感激
解决方案
尝试以这种方式在chartOptions中向yaxis添加标签:
labels: {
show: true,
formatter: (val) => { return new Date(val); }
}
并删除工具提示。
推荐阅读
- node.js - Chromium 浏览器实例即服务
- android - 将 proguard 与 Hyperledger Iroha 一起使用时,我的应用程序崩溃了
- nativescript - 删除 TabView 的上边框?
- html - 当围绕它进行排序时,Div 始终保持在父 div 的中心
- java - Java - 我需要一个自定义的 spring 过滤器,应该在 http 响应之后调用
- reactjs - 使用 Laravel 和 MySQL 作为后端在 reactjs 和颤振中保存和显示博客内容的最佳方法
- .net - 错误 <%@ Application Codebehind="Global.asax.cs" Inherits="Erpeo.MvcApplication" Language="C#" %>
- algorithm - 为什么在 Djkstra 算法中使用堆?
- flutter - 如何在 Flutter 中制作具有淡入淡出效果的轮播/滑块/图像切换器
- php - 使用路由 laravel 5.8 传递参数