Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

CSS Flex and jQuery

@Ifescohub

Desktop design screenshot for the Expenses chart component coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


I don't know how to use the JSON File. please, can anyone explain?.

Community feedback

Elaine 11,400

@elaineleung

Posted

Hi Udeh, the JSON file can be used in your JS file with fetch, like this:

fetch("./data.json")  // fetches data from the file
.then(response => {
   return response.json(); // a promise is returned
})
.then(data => {
  console.log(data) // you can use console.log the data to see what it is first
})

Here is an example of how I used JSON in this challenge:

fetch("./data.json")
.then(response => {
   return response.json();
})
.then(data => {
  data.map( info => {

    const barDiv = document.createElement("div")   // I created a colored bar in the chart
    barDiv.classList.add('bars__day-bar')   // added a class for styling the bar 
    barDiv.style.height = `${info.amount * 0.1595}em`  // used the JSON info to determine height

    dayDiv.appendChild(barDiv)   // append this barDiv to the individual dayDiv in my chart

  })
});

You can have a look at the rest of my code here: https://github.com/elaineleung/frontendmentor/blob/main/expenseschartcomponent/index.js

Hope this helps!

Marked as helpful

1

@Ifescohub

Posted

@elaineleung Thanks so much for the explanation. Your comment is very useful.

Just applied it and it worked.

Though some part of your code are too hard for me to understand, prolly because I'm new to it. Maybe with time, I will reach that level.

Thanks again

1
Elaine 11,400

@elaineleung

Posted

@Ifescohub You're welcome, glad I could help! :)

1

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord