javascript - 如何使用 ReactJS 添加基于用户表单输入的条形图
问题描述
我想根据用户的表单输入添加一个条形图。提交表单后,它应该显示图表。你们有人能帮我吗?
在标签中我想显示名称数据。在图表中,我想显示一个带有 MonthDays 和 Availablefordays 的条形图。
这是我到目前为止的代码:
import React, { useState } from 'react'
const Multipleinput = () => {
const [userInfo, setUserInfo] = useState({
Name: "",
MonthDays: "",
Availablefordays: ""
});
const [records, SetRecords] = useState([]);
const handleInput = (e) => {
const name = e.target.name;
const value = e.target.value;
setUserInfo({ ...userInfo, [name]: value })
}
const handleSubmit = (e) => {
e.preventDefault();
const newRecord = { ...userInfo, id: new Date().getTime().toString() }
SetRecords([...records, newRecord]);
setUserInfo({ Name: "", MonthDays: "", Availablefordays: "" });
}
return (
<div>
<form action="" onSubmit={handleSubmit} >
<label htmlFor="Name">Name</label>
<input type="text" value={userInfo.Name} onChange={handleInput}>
</input>
<label htmlFor="MonthDays">Month Days</label>
<input type="text" value={userInfo.MonthDays} onChange=
{handleInput}></input>
<label htmlFor="Availablefordays">Available for days</label>
<input type="text" value=
{userInfo.Availablefordays} onChange={handleInput}></input>
<button type="submit" >Save User</button>
</form>
解决方案
推荐阅读
- build - Bazel cc_toolchain 用于非 gnu TI DSP 编译器
- javascript - 像我 5 岁一样解释我 - ES6 Promises & async/await 差异,我的代码“正确”吗?
- clojure - 如何查找 Datascript 中的多基数属性是否包含元素?
- excel - 从高级过滤器副本的输出创建表
- amazon-web-services - AWS 静态网站托管:在站点已经工作后,找不到服务器 IP 地址
- bash - Bash 替换切断了字符串的结尾
- flutter - 在 Flutter 中,我使用 local_auth 0.6.2+3 包并实现了示例代码。单击身份验证按钮时出现以下错误
- .net - 从视图调用操作而不更改页面
- php - PHP内存限制每天两次恢复到2M
- haskell - 使用镜头测试地图成员资格