Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
Generar gráfico con clave de datos dinámica en Rechart

Basado en el siguiente código de ejemplo, he creado un gráfico de líneas.

 const {LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend} = Recharts; const data1 = [ {time: 10, pv: 2400}, {time: 10, amt: 1300}, {time: 20, pv: 500}, {time: 20, amt: 1350}, {time: 30, pv: 3200}, {time: 30, amt: 4400}, ]; const SimpleLineChart = React.createClass({ render () { return ( <LineChart width={600} height={300} margin={{top: 5, right: 30, left: 20, bottom: 5}}> <XAxis type="number" dataKey="name" domain={['auto', 'auto']} /> <YAxis/> <CartesianGrid strokeDasharray="3 3"/> <Tooltip/> <Legend /> <Line type="monotone" data={data1} dataKey="pv" stroke="#8884d8" activeDot={{r: 8}}/> </LineChart> ); } }) ReactDOM.render( <SimpleLineChart />, document.getElementById('container') );

Pero mi requisito real es pasar 'dataKey' (aquí 'pv', 'amt', etc.) dinámicamente sin codificación dura como 'pv' o 'amt'.

 response_arr.forEach((item, index) => { var category = response_arr[index].category; newArray.push({ time: response_arr[index].dateTime, {this.category}: response_arr[index].value }); })

Sin embargo, el fragmento de código anterior ( this.category ) no está permitido en javascript. ¿Alguien puede ayudarme a resolver este problema?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!