React line chart with hours removed
P粉828463673
P粉828463673 2023-08-18 15:37:22
0
1
408

I want to remove every three hours from the bottom of the rope chart. I'm using react-chart-js2. I'm using the .map function to display these numbers. Is it possible to display only every three of them? Chart

Here is the code that displays the hours:

const data = { labels: chart.prices?.map(x => moment(x[0]).format('h:mm a')), datasets: [{ data: chart.prices?.map(x => x[1]), backgroundColor: '#ffffff00', borderColor: 'rgb(79 70 229)', borderWidth: '2', pointBorderColor: '#ffffff00', tension: 0.4, fill: { target: "origin", // 3. Set the fill options above: "rgba(79, 70, 229, 0.0625)" } }] }

I want only every third number to be displayed

P粉828463673
P粉828463673

reply all (1)
P粉068174996

Replace every third item with an empty string.

let hours = chart.prices?.map(x => moment(x[0]).format('h:mm a')); for (let i=0; i<=hours.length; i++) { if((i+1) % 3 == 0){ hours[i] = ""; } }

Then in chart.js:

labels: hours,

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!