javascript - VictoryChart 不更改日期数据
问题描述
我有一个胜利图和两个坐标轴,按照这张图
https://formidable.com/open-source/victory/gallery/multiple-dependent-axes/
但问题是我无法更改日期数据,尽管我更改了日期
<VictoryAxis
crossAxis={true}
tickCount={12}
data={date}
tickFormat={(x) => {
console.log(x);
return x.toLocaleString("vn-vn", {
month: "short",
day: "numeric"
});
}}
/>
和日期数据
const date = [
{ x: new Date(2000, 3, 4) },
{ x: new Date(2003, 4, 17) },
{ x: new Date(2004, 1, 1) },
{ x: new Date(2005, 1, 1) },
{ x: new Date(2006, 1, 1) },
{ x: new Date(2007, 2, 1) },
{ x: new Date(2008, 1, 1) }
];
但它总是显示1 jan
,请帮助
这是现场演示和数据
https://codesandbox.io/s/chart2-11eut?file=/src/App.js:776-1010
太感谢了
解决方案
使用数组:
const date = [
new Date(2000, 3, 4),
new Date(2003, 4, 17),
new Date(2004, 1, 1),
new Date(2005, 1, 1),
new Date(2006, 1, 1),
new Date(2007, 2, 1),
new Date(2008, 1, 1)
];
将 JSX 修改如下:
<VictoryAxis
crossAxis={true}
tickValues={date}
tickCount={date.length}
tickFormat={(x) => {
return x.toLocaleString("vn-vn",
{month: "short", day: "numeric"})
}
}
/>
推荐阅读
- facebook-graph-api - 如何在 Facebook Graph API 中获取我的页面后跟的组列表
- python-3.x - DRF 在 POST 请求中使用字段值而不是默认值 (pk)
- sql - 使用sql对数据进行分类
- javascript - mapDispatchToProps 没有将 actionCreators 分派到所需的组件
- r - r - How to change the order of a factor within another factor - ggplot2
- python - How to make 3d (4 variable) ternary (pyramid) plot in R or Python?
- angular - 如何根据用户的输入即时过滤对象数组
- nstextview - 在 Swift 中使用 NSLayoutManager 隐藏 Markdown 字符
- php - Cron 尝试运行 php 命令但它出错
- java - 如何在 MongoDB 的 application.properties 中设置等待队列倍数和最大池大小