【发布时间】:2021-08-01 23:00:14
【问题描述】:
感谢您的宝贵时间。
我想做这个,你可以在图片中看到。
我有数组中标签的值和其他数组中 yAxes 的值。 标签显示一小时的 59 分钟,我只想显示分钟(05、10、15、20 ......等) 我只能在这个时间值中推入数组,但是当我将“时间”放在chartjs中的标签中时,图表只在yAxes中显示12个值,我想在yAxes中显示59个值并且只显示这个xAxes。 ..
如果我这样做:
import { Fragment } from "react";
import { Line } from "react-chartjs-2";
import "./GraficosDemo.css";
const GraficosDemo = ({ datosMeteoGraf, rotuloGrafico }) => {
var colors = [
"#007bff",
"#0097fc",
"#333333",
"#c3e6cb",
"#dc3545",
"#ed872d",
];
if (!datosMeteoGraf) return null;
const dataSetTWS = [];
const dataSetTWS_GUST = [];
const minutos = [];
//GRAFICO DE INTENSIDAD DE VIENTO
for (let i = 0; i < datosMeteoGraf.length; i++) {
dataSetTWS.push(datosMeteoGraf.TWS[i]);
}
//GRAFICO DE INTENSIDAD DE RACHAS DE VIENTO
for (let i = 0; i < datosMeteoGraf.length; i++) {
dataSetTWS_GUST.push(datosMeteoGraf.TWS_GUST[i]);
}
// console.log(dataSetTWS_GUST);
for (let i = 0; i < datosMeteoGraf.length; i++) {
if((new Date (datosMeteoGraf.TIME[i]).getMinutes()) % 5 === 0){
minutos.push(new Date(datosMeteoGraf.TIME[i]).toTimeString().slice(0, 5))
}
}
return (
<Fragment>
<Line
data={{
labels: minutos,
datasets:[
{
borderWidth: 0,
label: "Intensidad Última Hora",
data: dataSetTWS,
backgroundColor: "transparent",
borderColor: colors[1],
pointStyle: "dash",
},
{
borderWidth: 0,
label: "Intensidad Rachas de Viento",
data: dataSetTWS_GUST,
backgroundColor: "transparent",
borderColor: colors[4],
pointStyle: "dash",
},
],
}}
height={250}
options={{
maintainAspectRatio: false,
scales: {
yAxes: [
{
ticks: {
beginAtZero: true,
stepSize: 1,
},
},
],
xAxes: [
{
display:true,
}
]
},
}}
/>
</Fragment>
);
};
export default GraficosDemo;
我有这个:
push in time array only the minutes multiples of 5
但我想保留我的所有价值观并只显示这些标签。就像顶部的图片一样。
有人可以帮帮我吗? 谢谢
【问题讨论】:
-
如果你能得到答案,你能接受吗?
标签: javascript chart.js react-chartjs