去除小时的React折线图
P粉828463673
P粉828463673 2023-08-18 15:37:22
[React讨论组]
<p>我想要从绳图的底部去掉每三个小时。我正在使用react-chart-js2。我正在使用.map函数来显示这些数字。有可能只显示其中的每三个吗? 图表</p> <p>这是显示这些小时的代码:</p> <pre class="brush:php;toolbar:false;">const data = { labels: chart.prices?.map(x =&gt; moment(x[0]).format('h:mm a')), datasets: [{ data: chart.prices?.map(x =&gt; x[1]), backgroundColor: '#ffffff00', borderColor: 'rgb(79 70 229)', borderWidth: '2', pointBorderColor: '#ffffff00', tension: 0.4, fill: { target: &quot;origin&quot;, // 3. Set the fill options above: &quot;rgba(79, 70, 229, 0.0625)&quot; } }] }</pre> <p>我希望只显示其中的每三个数字</p>
P粉828463673
P粉828463673

全部回复(1)
P粉068174996

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

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,

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号