I would like to display a chart using any one of the two function depending on button click. The functions are this.contenidoNuevo() and this.contenidoNuevo2(). If the user clicks btn1 then chart of this.contenidoNuevo() would be displayed and if the user clicks btn2 then this.contenidoNuevo2(). Also, chart of this.conetnidoNuevo() should be displayed when rendering, since its the default. Thanks for your help.
Functions:
onClick1 = () => { return <> {this.contenidoNuevo()} </> } onClick2 = () => { return <> {this.contenidoNuevo2()} </> } render():
<div className="row" <button id="btn1" onClick={() => {this.onClick1()}}> Option 1 </button> <button id="btn2" onClick={() => {this.onClick2()}}> Option 2 </button> {this.contenidoNuevo()} </div> Function contenidoNuevo with chart:
contenidoNuevo = () => { var Obj = this.state.difference_days; var data0 = {} var data1 = {} return <> {Obj == 0 && <Card title="Conversaciones" chartType="line" labels={Object.keys(this.state.concurrency)} datasets={[ { label: 'Número de conversaciones actuales', fill: false, lineTension: 0.1, backgroundColor: '#F07C30', borderColor: '#FA6A01', borderCapStyle: 'butt', borderDash: [], borderDashOffset: 0.0, borderJoinStyle: 'miter', pointBorderColor: '#F07C30', pointBackgroundColor: '#FA6A01', pointBorderWidth: 1, pointHoverRadius: 5, pointHoverBackgroundColor: '#F07C30', pointHoverBorderColor: '#FA6A01', pointHoverBorderWidth: 2, pointRadius: 1, pointHitRadius: 10, data: Object.values(this.state.concurrency) }, { label: 'Número de conversaciones anteriores', fill: false, lineTension: 0.1, backgroundColor: '#FC4C0126', borderColor: '#FC4C0126', borderCapStyle: 'butt', borderDash: [], borderDashOffset: 0.0, borderJoinStyle: 'miter', pointBorderColor: '#C73C00', pointBackgroundColor: '#FC4C01', pointBorderWidth: 1, pointHoverRadius: 5, pointHoverBackgroundColor: '#FC4C01', pointHoverBorderColor: '#C73C00', pointHoverBorderWidth: 2, pointRadius: 1, pointHitRadius: 10, data: Object.values(this.state.horario_uso_before) } ]} /> } </> } Function contenidoNuevo2 with chart:
contenidoNuevo2 = () => { var Obj = this.state.difference_days; return <> {Obj == 0 && <Card title="Conversaciones" chartType="line" labels={Object.keys(this.state.horario_uso_before)} datasets={[ { label: 'Número de conversaciones actuales', fill: false, lineTension: 0.1, backgroundColor: '#F07C30', borderColor: '#FA6A01', borderCapStyle: 'butt', borderDash: [], borderDashOffset: 0.0, borderJoinStyle: 'miter', pointBorderColor: '#F07C30', pointBackgroundColor: '#FA6A01', pointBorderWidth: 1, pointHoverRadius: 5, pointHoverBackgroundColor: '#F07C30', pointHoverBorderColor: '#FA6A01', pointHoverBorderWidth: 2, pointRadius: 1, pointHitRadius: 10, data: Object.values(this.state.horario_uso_before) }, { label: 'Número de conversaciones anteriores', fill: false, lineTension: 0.1, backgroundColor: '#FC4C0126', borderColor: '#FC4C0126', borderCapStyle: 'butt', borderDash: [], borderDashOffset: 0.0, borderJoinStyle: 'miter', pointBorderColor: '#C73C00', pointBackgroundColor: '#FC4C01', pointBorderWidth: 1, pointHoverRadius: 5, pointHoverBackgroundColor: '#FC4C01', pointHoverBorderColor: '#C73C00', pointHoverBorderWidth: 2, pointRadius: 1, pointHitRadius: 10, data: Object.values(this.state.concurrency) } ]} /> } </> }