task2_q1
This stacked bar chart shows agricultural trade data for Afghanistan from 2014 to 2018, displaying Import, Export, Production, and Consumption values per year. Each bar segment represents one category, with colors distinguishing the four metrics. The visualization uses D3.js v7 with `d3.stack()` to compute the stacked series, `d3.scaleBand()` for the x-axis years, and `d3.scaleLinear()` for the y-axis values. Data is hardcoded in the script rather than loaded from the accompanying CSV file. The chart renders as SVG with axis generators `d3.axisBottom()` and `d3.axisLeft()`.
AI-generated descriptionD3.js Stacked Bar Chart - Agricultural Data
Overview
This project visualizes agricultural trade data using a stacked bar chart created with D3.js.
Files
- index.html - Main file containing the D3.js visualization.
- style.css - Styles for the visualization.
- README.md - Instructions on how to use the project.
- Export.csv - The dataset (source file).
Setup & Usage
- Open
index.htmlin a web browser. - The stacked bar chart will display
Import,Export,Production, andConsumptionover the years. - The colors represent different categories:
- Blue: Import
- Orange: Export
- Green: Production
- Red: Consumption
Dependencies
- D3.js (included via CDN)
Customization
- Modify the
dataarray inindex.htmlto use a different dataset. - Update
style.cssto change the chart appearance.
Preview
Stacked Bar Chart (Add a screenshot here)
License
This project is free to use and modify.
Enjoy exploring data with D3.js! 🚀