如何在React-Chartsjs-2中滚动X轴
我已经在react.js中实现了一个条形图,我想弄清楚当值越来越多的时候如何滚动x轴。在下图中,我有一些用户一天内进行的搜索值。到目前为止,我有100天以上的时间,我认为我的问题会更大,直到我们到达年底,X轴的价值更高。
我的图表代码和选项在下面。
const options = {
responsive: true,
plugins: {
title: {
display: true,
},
},
};
const dataForSearchBins = {
labels,
datasets: [
{
label: "Number of searches",
data: searchBins?.map((item) => item.value),
backgroundColor: "lightBlue",
},
],
};
<Stack>
<Text style={{ textAlign: "center" }}>{`Number of clicks per ${binSize.toLowerCase()}`}</Text>
<Bar options={options} data={data} />
<Box mb={6} />
</Stack>
I have implemented a bar chart in react.js and I want to figure out how I can scroll in x-axis when the values are more and more. In below chart I have some search values that user do in a day. Until now I have 100+ days and I think my problem will be bigger until we reach the end of the year when I will have more values in x-axis.
My code for the chart and the options are below.
const options = {
responsive: true,
plugins: {
title: {
display: true,
},
},
};
const dataForSearchBins = {
labels,
datasets: [
{
label: "Number of searches",
data: searchBins?.map((item) => item.value),
backgroundColor: "lightBlue",
},
],
};
<Stack>
<Text style={{ textAlign: "center" }}>{`Number of clicks per ${binSize.toLowerCase()}`}</Text>
<Bar options={options} data={data} />
<Box mb={6} />
</Stack>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 chartjs-plugin-zoom 为此。
注册Zoom插件后,修改
Options
对象。You can use chartjs-plugin-zoom for this.
After registering zoom plugin, modify the
options
object.