无法在 React apex-chart 中将时间戳转换为小时、分钟和秒
Unable to convert timestamp to hours minutes and secondes in React apex-chart
我正在使用 React 顶点图表创建一个图表,该图表将显示每个代理的平均响应时间。
我已经设法以时间戳格式获得结果,但我无法将其转换为小时、分钟和秒以在 yaxis 中显示,我已经检查了文档 docs link 但他们给出了示例仅限日期时间。
这是我使用下面的组件得到的结果
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;
我已经搜索过类似的问题,但没有成功,如果有人能帮助我,我将不胜感激
尝试将标签添加到yaxis 在 chartOptions 这样:
labels: {
show: true,
formatter: (val) => { return new Date(val); }
}
并删除 工具提示。
我正在使用 React 顶点图表创建一个图表,该图表将显示每个代理的平均响应时间。
我已经设法以时间戳格式获得结果,但我无法将其转换为小时、分钟和秒以在 yaxis 中显示,我已经检查了文档 docs link 但他们给出了示例仅限日期时间。 这是我使用下面的组件得到的结果
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;
我已经搜索过类似的问题,但没有成功,如果有人能帮助我,我将不胜感激
尝试将标签添加到yaxis 在 chartOptions 这样:
labels: {
show: true,
formatter: (val) => { return new Date(val); }
}
并删除 工具提示。