首页  >  问答  >  正文

去除小时的React折线图

<p>我想要从绳图的底部去掉每三个小时。我正在使用react-chart-js2。我正在使用.map函数来显示这些数字。有可能只显示其中的每三个吗? 图表</p> <p>这是显示这些小时的代码:</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>我希望只显示其中的每三个数字</p>
P粉828463673P粉828463673400 天前447

全部回复(1)我来回复

  • P粉068174996

    P粉0681749962023-08-19 11:48:31

    将每三个项目替换为空字符串。

    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] = "";
      }
    }

    然后在chart.js中:

    labels: hours,

    回复
    0
  • 取消回复