Giter VIP home page Giter VIP logo

expenses-chart-component's Introduction

Frontend Mentor - Expenses chart component solution

This is a solution to the Expenses chart component challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.

Table of contents

Overview

The challenge

Users can:

  • View the bar chart and hover over the individual bars to see the correct amounts for each day
  • See the current day’s bar highlighted in a different colour to the other bars
  • View the optimal layout for the content depending on their device’s screen size
  • See hover states for all interactive elements on the page
  • JSON data is used to dynamically size the bars on the chart

Screenshot

Desktop

Mobile

Links

My process

Built with

  • React - JS library
  • TailwindCSS - For styling
  • Flexbox
  • CSS Grid
  • Mobile-first workflow

What I learned

Custom TailwindCSS styles

I learned how to write custom Tailwind classes. I had values for padding, colors, font size, font weight, and border radius that differed from TailwindCSS default styling. I extended TailwindCSS' styles in tailwind.config.js. For example:

theme: {
    extend: {
        ...
        colors: {
            'soft-red': '#EC755D',
            'cyan': '#76B5BC',
            'pale-cyan': '#B4E0E5',
        }
        ...
    }
}

Dynamically generate the bar height

To generate the height of each bar, I created a simple one-variable equation using the day amount and bar height in pixels (according to the design). Solving for x, I got the ratio to multiply each date amount and rounded up to the nearest whole number.

const barHeight = `${Math.round(props.amount * 2.8661)}px`;

Using string templates, I was able to set the height with the calculated height.

<div 
    style={{height: barHeight}}
></div>

Author

expenses-chart-component's People

Contributors

semajthomasprimm avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.