1

Hello I want to pass my dynamically values like months like SEP,OCT,NOV and its sum value about user creation month vise. My chart working fine with giving manually values but when I give values with JSON map then its not working. My code with Manually which is working fine

   data: {
     labels:[ chartUsers[0]?.Month,chartUsers[1]?.Month,chartUsers[2]?.Month ],
     datasets:[
      {
    label: "2022",
    data: [chartUsers[0]?.totalUsers, chartUsers[1]?.totalUsers, chartUsers[2]?.totalUsers],
    maxBarThickness: 15
      }
          ]
     } 

But When I give values by loop then not working. My cod with loop is

    data: {
     labels:[ chartUsers.map(item => { return(item.Month+',')  }) ],
     datasets:[
      {
    label: "2022",
    data: [chartUsers.map(item => { return(item.totalUsers+',')  })],
    maxBarThickness: 15
      }
          ]
     }

Then this code is not working. Actually I want with values with loop. Can anyone help please with thanks

1 Answer 1

2

map function already returns array, so you should remove the brackets:

  data: {
    labels: chartUsers.map(item => { return(item.Month)  }) ,
    datasets:[
            {
          label: "2022",
          data: chartUsers.map(item => { return(item.totalUsers)  }),
          maxBarThickness: 15
            }
         ]
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot . Please up vote my question too with thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.