简体   繁体   English

如何从选项表单中更改图表?

[英]How to change graphs in react from an options form?

I am new in React and I want to change two graphs made in js depending on a form made with bootstrap form.我是 React 新手,我想根据使用引导程序表单制作的表单更改用 js 制作的两个图形。

My code in react is the following:我的反应代码如下:

 import React from 'react'; import Container from 'react-bootstrap/Container'; import Row from 'react-bootstrap/Row'; import Col from 'react-bootstrap/Col'; import Titulo from './Titulo/Titulo'; import Form from 'react-bootstrap/Form'; import Dona_etiquetas from './Graficas/Dona_etiquetas'; import Dona_etiquetas2 from './Graficas/Dona_etiquetas2'; import Linear_etiquetas from './Graficas/Linear_etiquetas'; import Tabla_etiquetas from './Graficas/Tabla_etiquetas'; import { Link } from "react-router-dom"; import { useState } from 'react'; function Seccion1Reporte1() { const [optionSelected, setOptionSelected] = useState('1mes'); const handleChange = event => { setOptionSelected(event.target.value); } //const tablaHeader1 = ["Número de registro","Número de errores","Etiquetas erróneas","Mensaje de error"]; //const tablaContenido1 = ["MT001", "4", "blc_aba", "Campo no es alfanumérico"]; return ( <> <Titulo texto="Reporte 1: Validación de Estructura del Reporte" /> <Container fluid={true}> <Row> <Col> <Form.Group style={{ width: '100%' }}> <Form.Control as="select" size="lg" custom> <option>Seleccionar periodo</option> <option value="1mes">1 mes</option> <option value="dos_once">2 - 11 meses</option> <option value="doce">12 meses</option> </Form.Control> <Form.Group style={ optionSelected != '1mes' ? { width: '50%' } : { width: '50%' }}> <Dona_etiquetas /> </Form.Group> <Form.Group style={ optionSelected == '1mes' ? { width: '50%' } : { width: '50%' }}> <Dona_etiquetas2 /> </Form.Group> </Form.Group> </Col> </Row> </Container> </> ) } export default Seccion1Reporte1;

I have not been able to change the graph from the options, only the two graphs appear at the same time.我无法从选项中更改图表,只有两个图表同时出现。

Here the image!这里的形象! 在此处输入图片说明

You can render them conditionally:您可以有条件地渲染它们:



{optionSelected == "1mes" && <Form.Group style={ optionSelected != '1mes' ? { width: '50%' } : { width: '50%' }}>
                            <Dona_etiquetas />
                        </Form.Group>}
{optionSelected != "1mes" && <Form.Group style={ optionSelected == '1mes' ? { width: '50%' } : { width: '50%' }}>
                            <Dona_etiquetas2 />
                        </Form.Group>}

**I GOT IT!!! **我知道了!!! I find the answer!!!我找到答案了!!! ** **

我知道了!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM