Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
Show Client Added According to Date Barchart Chart.js (I need perfect code optimization for it )

I need proper solution as the code that I have written is seems to be hard coded as multiple filter method is use for same scenario. Please help me to sort out as I am new to react. The output is dynamically rendered in bar chart.

 const ClientActivityChart = () => {
      const [clients, setClients] = useState([])
      const getClients = async () => {
        try {
          const res = await fetch('http://localhost:4000/api/addClients', {
            method: 'GET',
            headers: {
              'Content-Type': 'application/json',
            },
            credentials: 'include',
          })
          const data = await res.json()
          console.log(data)
          const filterJan = data.filter((item) => {
            let date = new Date(item.date)
            const month = date.toLocaleString('default', { month: 'long' })
            return month === 'January'
          })
          const filterFeb = data.filter((item) => {
            let date = new Date(item.date)
            const month = date.toLocaleString('default', { month: 'long' })
            return month === 'February'
          })
          const filterMarch = data.filter((item) => {
            let date = new Date(item.date)
            const month = date.toLocaleString('default', { month: 'long' })
            return month === 'March'
          })
          const filterApril = data.filter((item) => {
            let date = new Date(item.date)
            const month = date.toLocaleString('default', { month: 'long' })
            return month === 'April'
          })
         const filterJune = .........

          var dataItem = [
            filterJan.length,
            filterFeb.length,
            filterMarch.length,
            filterApril.length,
            filterMay.length,
            filterJune.length,
            filterJuly.length,
            filterAug.length,
            filterSep.length,
            filterOct.length,
            filterNov.length,
            filterDec.length,
          ]
          console.log(dataItem)
          setClients(dataItem)
        } catch (err) {
          console.log(err)
        }
      }
      useEffect(() => {
        getClients()
      }, [])

Here's a output. enter image description here

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda