React line chart with hours removed
P粉828463673
P粉828463673 2023-08-18 15:37:22
0
1
555
<p>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</p> <p>Here is the code that displays the hours: </p> <pre class="brush:php;toolbar:false;">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)" } }] }</pre> <p>I want only every third number to be displayed</p>
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