Git Product home page Git Product logo

d3barchart's Introduction

Contributors Forks Stargazers Issues MIT License LinkedIn


Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

Product Name Screen Shot

to create from scratch

npx create-react-app . --use-npm
npm i gh-pages --save-dev

or install from this repo

npm i
// to edit package.json
npm init
{
  "name": "project name",
  "scripts": {
    "start": "react-scripts start",
    "deploy": "npm run build && gh-pages -d build",
    "build": "react-scripts build"
  },
  "homepage": "https://UserName.github.io/projectName"
}
// npm run build
npm run deploy


  1. This Episode on Twitch
  2. FreeCodeCamp.com Front End Projects
  3. Markdown Cheatsheet
  4. The Essential Meta Tags for Social Media
  5. GitHub Pages

GitHub Pages Deploy & Domain: TraversyMedia
https://youtu.be/SKXkC4SqtRk

  1. @ScriptHammer on Twitter
  2. LinkedIn

ScriptHammer.com
https://ScriptHammer.com

(back to top)

Built With

(back to top)

Getting Started

This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.

Prerequisites

This is an example of how to list things you need to use the software and how to install them.

  • npm
    npm install npm@latest -g

Installation

  1. Get a free API Key at https://example.com
  2. Clone the repo
    git clone https://github.com/TurtleWolfe/turtlewolfe.git
  3. Install NPM packages
    npm install
  4. Enter your API in config.js
    const API_KEY = 'ENTER YOUR API';

(back to top)

Usage

Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.

For more examples, please refer to the Documentation

(back to top)

Roadmap

  • [] Feature 1
  • [] Feature 2
  • [] Feature 3
    • [] Nested Feature

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Your Name - @twitter_handle - dev.TurtleWolfe@gmail.co@email_client.com

Project Link: https://github.com/TurtleWolfe/turtlewolfe

(back to top)

Acknowledgments

(back to top)

d3barchart's People

Contributors

turtlewolfe avatar

Watchers

 avatar

d3barchart's Issues

Tool Tip and yScale?

Passing 9 out of 14, but I suspect they may be inter-related
failing on the last five

#10, #11 & #12

yScale.domain([yMin - 150, yMax + 1000]); 

I tried adjusting the yScale.domain but the more I played with the numbers, the further off they seemed to get..

yScale.domain([yMin , yMax]); 

meaning instead of these numbers being off by a couple of decimals, it was more like doubled.. I'll try to update with another screen capture when I'm testing again. Or at least get better references for which changes generated which numbers. But Min -150 and Max +1000 was the only thing even in the ballpark.

76867

relevant section? (less sure about this one)

  // // section 6 Adjusting the height and the width of the bars

  var yScale = d3.scaleLinear(); //create a linear scale
  yScale.range([HEIGHT, 0]); //set its visual range to 600 -> 0 (remember bottom of svg is 600px down from top)
  var yMin = d3.min(data, function (datum, index) { //get the minimum y data value...
    // console.log(datum[1]);
    return datum[1]; //by looking at the count property of each datum
  });
  var yMax = d3.max(data, function (datum, index) { //get the maximum y data value...
    // console.log(datum[1]);
    return datum[1]; //by looking at the count property of each datum
  });
  yScale.domain([yMin - 150, yMax + 1000]); //set the domain of yScale from yMin and yMax

#13 & #14
I'm getting a tooltip that shows the GDP and it has the id='tool-tip' so I'm not sure why it's still failing the first one under the tooltip. I tried changing title to tooltip but then it didn't even show up at all for mouseover. At least now it shows up, but still not passing the automation.

title

relevant section! more sure about this one..

  // // section 6 add a tooltip based on the Quarter of GDP's date

  d3.selectAll('rect') //find all rectangles
    .append("title")
    .attr('id', 'tooltip')
    .attr('data-date', function (datum, index) { //get the height of each rectangle...
      let QUARTER = datum[0];
      return QUARTER;
    })
    .text(function (datum) { //get the height of each rectangle...
      let QUARTER = datum[0];
      // console.log(datum[0]);
      // // console.log(QUARTER);
      return 'data-date: ' + QUARTER;
    }); //

This is one of the hints that made me think they could both be different manifestations of a related bug, it's seeing 1947 as 1981?
Screenshot from 2021-01-13 22-59-34

BarChart: Data Visualization with D3 Challenges at freeCodeCamp.com

repo: https://github.com/TurtleWolfe/D3BarChart
live demo: https://turtlewolfe.github.io/D3BarChart best viewed in Chrome

javaScript.js full file for reference and in case it's somewhere else

var WIDTH = 800;
var HEIGHT = 400;

// set width and height of svg
d3.select('svg')
  .style('width', WIDTH)
  .style('height', HEIGHT);

// fetch data
// // section 4 Making an AJAX request

d3.json('https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json').then(function (data) {

  // console.log(data);
  // console.log(data.data);
  data = data.data;
  console.log(data);
  //once data is retrieved...
  // // section 5 Using AJAX data to create SVG elements

  d3.select('svg').selectAll('rect') //select rectangles within svg (even if none exist)
    .data(data) //attach data to the rectangles
    .enter() //find the data elements that are not attached to rectangles
    .append('rect') //append rectangles for each data not attached to a rectangle
    .attr('class', 'bar'); //add attribute class='bar' to each rectangle


  // // section 6 Adjusting the height and the width of the bars

  var yScale = d3.scaleLinear(); //create a linear scale
  yScale.range([HEIGHT, 0]); //set its visual range to 600 -> 0 (remember bottom of svg is 600px down from top)
  var yMin = d3.min(data, function (datum, index) { //get the minimum y data value...
    // console.log(datum[1]);
    return datum[1]; //by looking at the count property of each datum
  });
  var yMax = d3.max(data, function (datum, index) { //get the maximum y data value...
    // console.log(datum[1]);
    return datum[1]; //by looking at the count property of each datum
  });
  yScale.domain([yMin - 150, yMax + 1000]); //set the domain of yScale from yMin and yMax


  // // section 6 Adjusting the height and the width of the bars

  d3.selectAll('rect') //find all rectangles
    .attr('height', function (datum, index) { //set the height of each rectangle...
      //...by getting the count property of each datum
      //converting it to a visual value, using yScale
      //(remember, when using yScale as it is set up, a large data value will give you a small visual value and vice versa)
      //then subtract that value from HEIGHT
      //this will make a large bar for a large data value
      console.log(datum[1]);
      return HEIGHT - yScale(datum[1]);
    });


  // // section 6 Adjusting the height and the width of the bars

  d3.selectAll('rect') //find all rectangles
    .attr('data-gdp', function (datum, index) { //set the height of each rectangle...
      let GDP = datum[1];
      // console.log(datum[1]);
      // // console.log(GDP);
      return GDP;
    });

  // // section 6 Adjusting the height and the width of the bars

  d3.selectAll('rect') //find all rectangles
    .attr('data-date', function (datum, index) { //set the height of each rectangle...
      let QUARTER = datum[0];
      // console.log(datum[1]);
      // // console.log(QUARTER);
      return QUARTER;
    });

  // // section 6 add a tooltip based on the Quarter of GDP's date

  d3.selectAll('rect') //find all rectangles
    .append("title")
    .attr('id', 'tooltip')
    .attr('data-date', function (datum, index) { //get the height of each rectangle...
      let QUARTER = datum[0];
      return QUARTER;
    })
    .text(function (datum) { //get the height of each rectangle...
      let QUARTER = datum[0];
      // console.log(datum[0]);
      // // console.log(QUARTER);
      return 'data-date: ' + QUARTER;
    }); //


  // // section 7 Adjusting the horizontal and the vertical placement of the bars

  var xScale = d3.scaleLinear(); //create the xScale
  xScale.range([0, WIDTH]); //set the range to 0->800
  xScale.domain([0, data.length]); //set the domain from 0 to the number of data elements retrieved
  d3.selectAll('rect') //select all rectangles
    .attr('x', function (datum, index) { //set the x position of each rectangle...
      return xScale(index);//by converting the index of the element in the array to a point between 0->800
    });


  // // section 7 Adjusting the horizontal and the vertical placement of the bars

  d3.selectAll('rect') //select all rectangles
    .attr('y', function (datum, index) { //set the y position of each rectangle...
      //by converting the count property of the datum to a visual value
      //(remember, when using yScale as it is set up, a large data value will give you a small visual value and vice versa)
      return yScale(datum[1]);
    });


  // // section 8 Making the width of the bars dynamic

  d3.selectAll('rect') //select all rectangles
    .attr('width', WIDTH / data.length); //set the width of all rectangles to be the width of the SVG divided by the number of data elements


  // // section 9 Changing the color of the bar based on data

  var yDomain = d3.extent(data, function (datum, index) { //set the y domain by getting the min/max with d3.extent
    return datum[1]; //... and examining the [1] property of each datum
  });
  var colorScale = d3.scaleLinear();//create a linear scale
  colorScale.domain(yDomain); //the domain is the yDomain
  colorScale.range(['#00cc00', 'blue']); //the visual range goes from green->blue
  d3.selectAll('rect') //select all rectangles
    .attr('fill', function (datum, index) { //set the fill of each rectangle
      return colorScale(datum[1]); //by converting the [1] property of the datum to a color
    });


  // // section 10 Adding axes

  var leftAxis = d3.axisLeft(yScale); //create a left axis generator using the yScale
  d3.select('svg') //select the svg
    .append('g').attr('id', 'x-axis') //append a <g> tag to it with id=left-axis
    .call(leftAxis); // create a left axis within that <g>


  // // section 10 Adding axes

  var skillScale = d3.scaleBand(); //create a scale band that will map skills to horizontal positions
  var skillDomain = data.map(function (skill) { //create an array of skill strings
    console.log(skill[0]);
    return skill[0];
  });
  skillScale.range([0, WIDTH]); //set the range of the skillScale to 0->800
  skillScale.domain(skillDomain); //set the domain to be the array of skill strings


  // // section 10 Adding axes

  var bottomAxis = d3.axisBottom(skillScale); //create a bottom axis generator that uses the skillScale
  d3.select('svg') //select the svg
    .append('g').attr('id', 'y-axis') //append a <g> tag to it with id=bottom-axis
    .call(bottomAxis) // create a bottom axis within that <g>
    .attr('transform', 'translate(0,' + HEIGHT + ')'); //move it to the bottom of the svg

});

ajax call of Array instead of Object

The Book I'm reading sets height from the object calling count from an object in an array

[
  {
    "name": "HTML",
    "count": 21
  },
  {
    "name": "CSS",
    "count": 17
  },
  {
    "name": "Responsive Web Design",
    "count": 17
  }
]

The assignment I'm trying to complete needs to set the height from an array in an array, where the original code references count as the 2nd entry in the object, I need to change it to gdp which is the 2nd entry in an array of arrays. Specifically, this line where it returns datum.count.. I should return datum[1]?

"data": [
    [
      "1947-01-01",
      243.1
    ],
    [
      "1947-04-01",
      246.3
    ],
    [
      "1947-07-01",
      250.1
    ],
    [
      "1947-10-01",
      260.3
    ]
]

BarChart: Data Visualization with D3 Challenges at freeCodeCamp.com

repo
live demo,

javaScript.js

d3.json('https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json').then(function (data) {

  // console.log(data);
  // console.log(data.data);
  data = data.data;
  console.log(data);
  //once data is retrieved...
  // // section 5 Using AJAX data to create SVG elements

  d3.select('svg').selectAll('rect') //select rectangles within svg (even if none exist)
    .data(data) //attach data to the rectangles
    .enter() //find the data elements that are not attached to rectangles
    .append('rect'); //append rectangles for each data not attached to a rectangle


  // // section 6 Adjusting the height and the width of the bars

  var yScale = d3.scaleLinear(); //create a linear scale
  yScale.range([HEIGHT, 0]); //set its visual range to 600 -> 0 (remember bottom of svg is 600px down from top)
  var yMin = d3.min(data, function (datum, index) { //get the minimum y data value...
    return datum.count; //by looking at the count property of each datum
  });
  var yMax = d3.max(data, function (datum, index) { //get the maximum y data value...
    return datum.count; //by looking at the count property of each datum
  });
  yScale.domain([yMin - 1, yMax]); //set the domain of yScale from yMin and yMax
});

template for issues with D3BarChart

BarChart: Data Visualization with D3 Challenges at freeCodeCamp.com

repo
live demo,

javaScript.js

  // // section 6 Adjusting the height and the width of the bars

  var yScale = d3.scaleLinear(); //create a linear scale
  yScale.range([HEIGHT, 0]); //set its visual range to 600 -> 0 (remember bottom of svg is 600px down from top)
  var yMin = d3.min(data, function (datum, index) { //get the minimum y data value...
    return datum.count; //by looking at the count property of each datum
  });
  var yMax = d3.max(data, function (datum, index) { //get the maximum y data value...
    return datum.count; //by looking at the count property of each datum
  });
  yScale.domain([yMin - 1, yMax]); //set the domain of yScale from yMin and yMax

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.