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

Expenses chart component

BreinerJTβ€’ 530

@BreinerJT

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


This challenge took me a while because I don't know much about async / await functions, I don't feel good about my knowledge in this kind of functions so if you know where can I learn or read more about this I would really appreciate it if you share it with me. Any feedback is welcome!

Community feedback

Abreham Nigussieβ€’ 470

@DreamCoder7

Posted

Hey, BreinerJTπŸ‘‹

Nice effort on this challenge!πŸ‘

Overall, your solution looks great! One small thing I'd like suggest is that instead of outputting the chart data one by one using html like you did, you can dynamically output from JavaScript. Also you can add a Gaurd clause incase if the user failed to load, More about Gaurd clause

async function getData(url){
    let fetchData = fetch(url)
    let response = await fetchData;
// Adding Gaurd clause 
    if (!response.ok) return;
    let data = await response.json()
    return data;
}

 async function getCharts(){
    const chart = document.querySelector(".charts");
    const data = await getData('data.json');

    let html = null;
    data.forEach(e => {
       html =  `
        <div class="chart-container">
            <p class="day" data-id="mon">${e.day}</p>
            <div class="js-chart chart" id="mon" style="height: ${e.amount}%"></div>
            <label class="js-label" for="mon">${e.amount}</label>
        </div>
        `
    chart.insertAdjacentHTML("afterbegin", html);
    });

// Not needed
/*
    const amounts = data.map(e => e.amount)
    let maxValue = Math.max(...amounts)
    let heights = amounts.map(e => e / maxValue * 100)
    charts.forEach((value, index) => {
        value.style.height = `${heights[index]}%`
    })
    charts[day].classList.add("current-day")
    labels.forEach((value, index) => {
        value.textContent = `$${amounts[index]}`
     })
*/
}

getCharts()

Hope that helps!πŸ€—

Happy coding.😎

Marked as helpful

0

BreinerJTβ€’ 530

@BreinerJT

Posted

Hi redstorm-hub, I was thinking about adding the chart output from Javascript but I didn't find a good way to do it, thanks for showing me this one.

0
Abreham Nigussieβ€’ 470

@DreamCoder7

Posted

@BreinerJT

My pleasure!πŸ˜‰

0
Dimitar Pavlovβ€’ 310

@DimiPavlov

Posted

Hello BreinerJT and congratulations on completing the challenge.

I really like your idea of switching the colors of the charts, looks very cool. Just a small suggestion for a better user experience is maybe to add 'cursor: pointer' for the hover effect.

Marked as helpful

0

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