-6ren">
gpt4 book ai didi

reactjs - 我必须绘制收入和支出图表,只想绘制当年的图表。 react Sequelize

转载 作者:行者123 更新时间:2023-12-03 22:21:04 24 4
gpt4 key购买 nike

我必须绘制我的收入和支出图表,只希望绘制当前年份。通过允许图表无限滚动并不仅仅指定显示的年份。
api

router.get("/revenuelimit", async (req, res) => {
let result = await revenue.findAll({ limit: 5 , order: Sequelize.literal("id DESC") });
res.json(result);
console.log(result)
});
// January
router.get("/January", async (req, res) => {
let result = await revenue.findAll({
where: {
createdAt: {
[Op.between]: [ "2019-12-31 19:30:00.000 +00:00", "2020-01-30 19:30:00.000 +00:00"]},}});
res.json(result);
// res.json(result);
console.log("January");
});

// February
router.get("/February", async (req, res) => {
let result = await revenue.findAll({
where: {
createdAt: {
[Op.between]: [ "2019-01-31 19:30:00.000 +00:00", "2020-02-28 19:30:00.000 +00:00"]}}});
res.json(result);
// console.log(result);
});
获取Axios
 componentDidMount = async() => {
// Revenues
await httpClient
.get ("http://localhost:8085/api/v1/revenue/revenue")
.then((e) => this.setState({GetRevenue: e.data}));
console.log(this.state)

await httpClient
.get ("http://localhost:8085/api/v1/revenue/revenuelimit/")
.then((e) => this.setState({GetRevenuing: e.data}));

// month
await httpClient
.get ("http://localhost:8085/api/v1/revenue/January")
.then((e) => this.setState({January: e.data}));
await httpClient
.get ("http://localhost:8085/api/v1/revenue/February")
.then((e) => this.setState({February: e.data}));
await httpClient
.get ("http://localhost:8085/api/v1/revenue/March")
.then((e) => this.setState({March: e.data}));
await httpClient
.get ("http://localhost:8085/api/v1/revenue/April")
.then((e) => this.setState({April: e.data}));
await httpClient
.get ("http://localhost:8085/api/v1/revenue/May")
.then((e) => this.setState({May: e.data}));
await httpClient
.get ("http://localhost:8085/api/v1/revenue/June")
.then((e) => this.setState({June: e.data}));
await httpClient
.get ("http://localhost:8085/api/v1/revenue/July")
.then((e) => this.setState({July: e.data}));
await httpClient
.get ("http://localhost:8085/api/v1/revenue/August")
.then((e) => this.setState({August: e.data}));
await httpClient
.get ("http://localhost:8085/api/v1/revenue/September")
.then((e) => this.setState({September: e.data}));
await httpClient
.get("http://localhost:8085/api/v1/revenue/October")
.then((e) => this.setState({October: e.data }));
await httpClient
.get ("http://localhost:8085/api/v1/revenue/November")
.then((e) => this.setState({November: e.data}));
await httpClient
.get ("http://localhost:8085/api/v1/revenue/December")
.then((e) => this.setState({December: e.data}));
}
我在每个月的第一天到每个月的月底检索信息
图表栏
const data = {
labels: [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'],
datasets: [
{
label: 'รายรับ',
fill: true,
lineTension: 0.5,
backgroundColor: 'rgba(75,192,192,1)',
borderColor: 'rgba(75,192,192,1)',
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: 'rgba(75,192,192,1)',
pointBackgroundColor: '#fff',
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: 'rgba(75,192,192,1)',
pointHoverBorderColor: 'rgba(220,220,220,1)',
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 10,
data: [ Januarys ,
Februarys,
Marchs,
Aprils,
Mays,
Junes,
Julys,
Augusts,
Septembers,
Octobers,
Novembers,
Decembers
]
},
一月的信息是 2019 年,十月是 2020 年的信息。我只想显示当前年份。
enter image description here

最佳答案

在 2 月的 API 调用中,您将获取从 2019 年 1 月 31 日到 2020 年 2 月 28 日的所有数据点。您必须将此处的范围更改为 2020 年 1 月 31 日(或 2020 年 2 月 1 日)。
另外:2020 年是闰年,所以 2 月的最后一天是 29 日,

// February
router.get("/February", async (req, res) => {
...
[Op.between]: [ "2020-01-31 19:30:00.000 +00:00", "2020-02-29 19:30:00.000 +00:00"]}}});
...
});

关于reactjs - 我必须绘制收入和支出图表,只想绘制当年的图表。 react Sequelize ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64383344/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com