
Learn to build interactive charts with D3 and Angular, from scratch to reusable visualizations, including scatter plots, bar charts, pies, maps, and tooltips.
Develop interactive charts with D3 and Angular, from SVG basics to bar, line, scatter, and pie charts, including update patterns, tooltips, and interactive legends.
Having a good environment is a step further into developing quality software. We will install Visual Studio Code with some essentials extensions + node.js + Github desktop + Angular cli
Install node from nodejs.org and install the angular cli globally, then verify versions with node -v and ng version. Git is optional for accessing the GitHub repository.
Our first project, DashboardOne, will be our support to start delving into svg and introduce d3.js to angular.
Run the serve command to launch the Angular project locally on localhost:4200, and note the slight starting-point difference caused by the Angular version, while the coding approach remains the same.
Having created our project we will now add the d3 and bootstrap npm dependencies.
We will be using bootstrap as a support library to simplify the html coding so we can focus more on d3.
In this lesson we will create the dashboard component. We will be adding our test charts to visualize our work while learning about d3
Decompose charts into simple components: circles, lines, rectangles, and text, and position and style them to create interactive charts in Angular using D3. The same elements build different chart types.
Why choosing the SVG format? What advantages does it bring to our charts?
Generate the first chart by creating a chart component in the charts folder, add it to the dashboard, and render an orange svg that fills the component.
Map a data array to SVG rects to create a column chart. Style the bars with inline or CSS and adjust x and y positions; note they render upside down.
Invert the y axis in svg charts by computing each rectangle's y as the svg height minus its height, and generate the rectangles with an Angular for loop.
Bind data to svg rectangles using ngFor in Angular to create dynamic bars, binding x to index, height to data values, and update automatically when data changes.
Replace the hardcoded chart width with a component variable in Angular, include the label and X attributes for exposition, and observe the chart resize with width as defined by data.
Resize the rectangles to fit the svg by setting each width to the svg width divided by the number of rectangles, using angular elementRef and getBoundingClientRect to adapt on init.
Scale chart heights by mapping data values to pixels using a 250-pixel reference, compute the max with the spread operator, and update the rectangle heights and y positions.
Learn to add padding between bars by setting bandwidth and padding as percentages of the step, define inner and outer padding, and adjust positions for responsive charts.
Define margins to create space around the chart for titles, labels, axes, and legends, enabling a proper bar chart within the svg.
Define left, right, top, and bottom margins; compute inner width and height from the SVG dimensions; update dimensions accordingly and reserve space for legends.
Learn how SVG line elements use x1, y1 and x2, y2 to define start and end, style with stroke and stroke-dasharray, and animate all parameters with CSS.
Understand how the SVG path uses the D attribute as a command string, including M, Z, L, H, V, C, Q, A. Learn styling with stroke, fill, opacity, and stroke-dasharray.
Explore svg path commands with d3 and Angular, including move, line, horizontal and vertical lines, cubic and quadratic bezier curves, and arc parameters with flags to generate figures.
Create an svg project to test svg path and add a grid. Add horizontal and vertical grid lines every 100 pixels, style with a dashed stroke, and control opacity.
Learn how to build polygons with SVG path commands, including move, line, horizontal and vertical variants, relative versions, and closing with Z, plus setting stroke and fill.
Create non-polygon svg paths using quadratic and cubic bezier curves with control points and end points, styled with a blue stroke and white fill.
Explore the SVG path arc command (A) with rx, ry, x-axis rotation, large-arc-flag, sweep-flag, and end coordinates, demonstrating how radius and endpoints define elliptical or circular arcs in paths.
Explore the svg text element to label charts with x and y positioning, rotation, font size, color, and text anchor for alignment; also render curved labels with a text path.
Add x-axis labels to the chart by creating a labels array, binding it to text elements, and positioning them with margins and inner height in a D3 and Angular chart.
Add a horizontal axis by drawing an SVG line with x1, y1, x2, y2 coordinates, style it with CSS stroke on the x axis, and position it at y=50.
Learn to make a chart input-driven using ngOnChanges, resize on data changes, and refactor to SetParams for API data and D3 integration.
Connect to an API via an Angular service using http get, import http client module, and inject the API service; add two charts with data one and data two.
Learn to fetch and display data from an api using a fake data api, parse json, and bind it to charts with rxjs observables, map, and the async pipe.
The SVG specs. Basic elements: Rect, Circle, Line, Path, Polyline
To better understand how svg works, we will create a basic column chart by manually writing all the elements
In this lesson we will introduce d3 to angular and learn how to create the same column chart by using d3.
D3 keywords: select, selectAll, enter, append
Harness d3 select and selectAll to manipulate svg elements and add rectangles from data; select returns the first match, selectAll returns all, and empty selections occur when none exist.
Explore the d3 update pattern by binding data to a selection, using enter and exit with groups to append three rectangles for data 10, 20, and 30.
Learn the d3 update pattern, handling selections, enter and select all to update rect attributes like width and height across the new and old svg state.
Bind data to rectangles with d3, use enter to set height 10,20,30 by index, position with i times width and padding, then style with blue fill using .style() and .attr().
Discover how to update an existing D3 chart by appending rectangles, using arrow functions for x, binding data with enter, and styling with a blue fill.
Discover why D3-generated rectangles ignore Angular component styles due to missing meta information and learn to apply styling via inline styles or setting view encapsulation to None for global CSS.
Explore the D3 update pattern to handle changing data by updating existing elements, appending new ones with enter, and managing removals with exit to reflect data changes in a chart.
Learn how the D3 update pattern handles exit selections by removing elements, updating remaining rectangles’ heights with accessor functions, and properly clearing attributes using null.
Recreate chart two using D3 by importing input data from Angular core, wiring data into rectangles based on employee age, and handling undefined data with ngOnChanges and a draw method.
Use d3 scaleLinear to map a data domain to a visual range for chart rectangles, update scales with data changes, and apply them using svg dimensions and reverse ranges.
Apply scaleLinear to map employee age and salary to chart coordinates, fix variable usage for height and y, and use max salary to scale rectangles for consistent visuals.
Apply a scaleBand to map discrete ids to positions, using an ordinal domain and a 0 to width range. Define bandwidth and set inner padding to 0.2 for bar spacing.
Add left, right, top, and bottom margins to the chart and adjust the x domain and y range with inner width and inner height.
Fixing a bug in interactive charts with D3 and Angular demonstrates correcting margins and inner width, reworking the axis range, and positioning elements by updating left properties in the view.
Learn to group SVG elements with the g container, applying a single transform to translate all children by margins using inner width and inner height as origin.
Learn to simplify d3 charts in angular by using a data container. Translate for margins, place rectangles, and use inner height for sizing.
Discover the d3 axis, its four position types, and how to customize styling by selecting elements, applying properties, and appending axes to containers using scales.
Add a bottom horizontal axis to chart 3 by creating an x axis container, defining the x scale, and applying a set axis to the SVG.
Practice adding a vertical y axis to the chart in d3 by creating a y axis container and a left-positioned y axis, then adjust the left margin for proper fit.
Learn to customize D3 axes beyond default styles by using axis methods and post-selection, controlling tick counts, formats, and custom tick values mapped from the scale’s max.
Explore customizing D3 axis ticks by adjusting inner and outer tick sizes and padding, adding grids, and formatting values with currency and locale. Learn how SVG ordering affects grid placement.
Style D3 axis grids and ticks, apply selective styling to lines only, and add a rotated y-axis label by wrapping text in a container and positioning it with margins.
Replace axis ids with employee names by binding names to tick elements, rotate labels 45 degrees, adjust margins and translation, and implement set labels to organize chart for future data.
Explore the D3 update pattern, mastering enter, update, and exit as you implement a click to toggle between alphabetical and salary-sorted charts, and learn when to sort for clarity.
This lecture demonstrates the d3 update pattern to toggle between full and filtered data using a getter and a data state, updating enter, update, and exit to redraw the chart.
Learn how the d3 update pattern binds data to bars and uses enter, update, and exit selections, with colors illustrating each phase.
Master the d3 update pattern by binding data with a key, entering, updating, and removing bars, and applying transitions to reflect data changes in an interactive chart.
Sorts charts by salary in descending order, and switches to alphabetic sorting by employee name on click, using a compare function for numbers (B minus A) and strings (lexical comparison).
Animate d3 charts with transitions, updating svg rect attributes like x, y, width, and height. Explore how keys govern bar movement and axis animation timing, including 500 ms transitions.
Learn to transition the x axis in a d3 and angular chart by creating an update x axis function, applying the transition, and using post selection to animate the axis.
fix a bug in the d3 and angular chart by preventing repeated containers on updates, move label creation to set elements, and set a bold chart title.
Build an interactive scatter plot using iris data set loaded from a local file or api, with two dropdowns for x and y axes, color by category, and animated updates.
Add the iris dataset to the API by implementing a get iris method that fetches a CSV from GitHub, parses it into JSON objects, and applies a three-time retry.
Define the iris data in the app component by fetching it from the service, subscribe to the API, and load a 150-line CSV dataset with columns.
Implement in-chart dropdowns for a D3 and Angular chart, managing two selects (x and y) inside the chart via a short form component, with responsive styling.
Finish the dropdowns in the interactive chart by wiring two selections, x and y, to capture changes, populate options from columns, handle empty data, and prepare the update chart method.
Build a scatterplot step by step by following the anatomy of the chart, including axes, labels, circles, and two buttons, using an incremental lesson sequence and downloadable code.
Import D3, configure the host element and SVG canvas, and initialize the scatterplot in Angular on ngOnInit using ElementRef and the D3 library.
Create empty methods for set dimensions, set elements, set params, set labels, set axis, and draw to structure the svg chart before adding data.
Learn to implement update chart for a D3 Angular scatterplot by running set params, set labels, set axes, and draw when data changes, with ng on changes and svg readiness.
Implement setDimensions by deriving the svg's bounding client rect to set dimensions and margins, compute inner width and inner height by subtracting margins, and apply a viewBox for basic resizing.
Implement the setElements method to create and translate data, x axis, and y axis containers, then add and align x and y labels using margins, inner width, and inner height.
Implement the scatterData getter to produce numeric x and y points from the selected sepal length and sepal width, returning an empty array until both values are chosen.
Define x and y linear scales with domains and inverted ranges using inner width and height, compute max values from data with the D3 math function, and finalize parameters.
Implement the setLabels function to update the x and y label text from the selected options, handle empty selections, and rotate the labels by -90 degrees in the SVG.
Configure the x and y axes with five ticks, dashed horizontal lines, and appropriate margins; apply a 500 milliseconds transition to animate updates and refine tick styling via CSS selectors.
Explore the SVG circle element, focusing on cx, cy and radius r, and style with fill, stroke, stroke width, fill opacity, stroke opacity, and animate using D3 with css properties.
Implement draw method using D3 update pattern: bind data, enter, merge, and exit to render circles in data container, with radius 3, fill #004494, opacity 0.4, and 500 ms transitions.
Address the max value bug by guarding the dot x value and max value so values are defined or default to one, avoiding the not iterable error in the chart.
Add a color scale for species by using the D3 scale ordinal with the category ten scheme to define domain and range and assign three colors based on species.
Define an ordinal color scale and set its domain to the unique species, then apply colors to circles in the scatter chart using the ten colors, handling missing data gracefully.
The src for the angular initial setup, already with chart 5, is available here in the src.zip
Learn to fetch covid-19 data with an API or local JSON, wiring a getCovidData method in Angular, and integrate it into an app component for an interactive chart.
Add a chart component in Angular by generating a new charts component, wiring input data from Angular core, and embedding the Covid data dashboard in the app HTML.
Define the line chart structure using D3 and Angular, avoid spaghetti code by applying the update pattern to the legend and lines, and parse time strings for readable axis formatting.
Learn how to add d3 to an angular chart by importing these three, wiring the host and svg in the component and view, and setting view encapsulation to none.
Implement chart methods by setting dimensions, elements, params, labels, axis, legend, and draw, then update the chart on changes and initialize on init.
Implement the setDimensions method to compute inner width and inner height from the SVG and margins, define the margins object, and add a viewBox for consistent rendering.
Learn how to implement the setElements in interactive D3 charts by adding data, legend, axis, and title containers, configuring margins and positions for a clean, reusable chart layout.
Explain d3 time concepts by converting strings to dates with timeParse and formatting them with timeFormat, while configuring x time scales, y linear scales, and color scales.
Learn how to parse and format dates with d3 timeParse in an Angular chart workflow, including handling JSON data, API calls, and custom time formats.
Define three d3 scales—the x time scale, the y linear scale, and colors ordinal scale—and set their domains and ranges, including color domain with d3 scheme category ten.
Define the x domain from dates, handle null data, and build multiple line series (hospitalized, deaths, hospitalized currently) with date/value points for SVG paths.
Define the y scale domain from zero to the data maximum, compute max values across each series from the line data, and set the color domain and axis accordingly.
Implement the set axis for the x and y axes, format x ticks every two months using time months, and apply tick format to remove the dollar symbol.
Implement the D3 line generator to draw three svg path elements by using x and y accessors, applying scales, and handling missing values with a define function.
Implement the setLabels to display the title 'COVID-19 Evolution in us' and apply consistent styling with font size 12 pixels and bold weight.
Learn to build an interactive legend for charts with D3 and Angular by creating items with icons and labels, handling hover and click, and updating via enter, update, and exit.
Bind data to legend items, create entering elements, append circles and text, and position with padding and radius; merge updates colors and labels for all legend items.
Reposition the legend in an interactive D3 and Angular chart by recalculating item widths, padding, and centering the legend for accurate alignment.
Simplify legend handling in a D3 and Angular chart by extracting legend item generation into a dedicated method, merging selections, and binding mouse over and click events for logging.
Implement mouse over and click events to manage default, over, and inactive states, highlighting hovered legend lines and toggling visibility based on selected data and active status.
Explore how to drive an interactive chart with an active boolean array, filtering lines by index to toggle visibility, and observe automatic chart updates as you disable or re-enable lines.
Bind the legend onClick to receive the event and item name, toggle the corresponding active line by index, and redraw the chart after each toggle in d3 and angular.
Highlight the corresponding line when hovering a legend item by adjusting opacity and stroke width, while fading other lines and resetting on mouse leave using overline logic in D3.
Improve chart usability by dimming legend items when inactive and ensuring disabled items don’t affect the chart, updating styles only for active lines to provide a clear visual cue.
Add transitions to lines and scales in the D3 Angular chart by keying data with line names, and enhance the legend with opacity and hover bold cues.
Create a pie and donut chart to illustrate data-driven, reusable charts with d3 and angular. Master the arc and pie helpers, and use custom interpolations for smooth transitions.
Define the api service to fetch browser share data from assets/browsers.json and expose it as an observable in the app component, then subscribe and log the result for pie chart.
Add a chart component to an Angular app by creating an SVG with class short six, importing ElementRef, configuring view encapsulation none, binding input data, and rendering with D3.
Explore building pie and donut charts with d3 and angular, including arc paths, responsive sizing, color scales, and a right legend, with hover and legend toggling interactions.
Define a stable pie data structure with title and data points (id, label, value) to drive arc sizes and map API data into the donut chart.
Convert browser data to pie data by defining interfaces for pie data elements, mapping data into id, label, and value, and using RxJS map for asynchronous updates.
Add a dropdown to select the data for the chart, bind a change event, and use a pie helper to map the selected value to the chart update.
Add the svg container with data and legend containers, the title, pie, and arc, then define scales and colors, and manage state with hidden IDs and inputs.
Define the config interface for a donut chart by outlining inner radius coefficient, hidden opacity, legend item properties, transition timing, and arc attributes, then move margins into the config.
Explore implementing chart methods in a D3 and Angular setup, including setting the svg dimensions, elements, legends, and drawing, with update chart and highlight interactions on data or config changes.
Compute chart dimensions using the SVG's bounding client rect to derive inner width and height after margins, then calculate radius and inner radius, and position chart containers.
Add data container, legend container, and title text to SVG, then position them with transform translate using margins and inner width and height. Center the title with text anchor middle.
Explore how the d3 arc and d3 pie generators convert data into svg arcs and paths using inner and outer radii, start and end angles, pad angles, and color scale.
Define setParams to initialize an arc generator with inner and outer radii, a pie generator with a value, and a category ten ordinal color scale with IDs.
Learn to implement the set labels method by extracting the title, ensure set dimensions and set elements run on ngOnInit, and then update the chart.
Draw a pie chart with D3 using the draw method by binding data, computing pie data with start and end angles, and applying the join-based update pattern for arcs.
Debug and fix a d3 data-join bug by ensuring new path elements receive the class data, so updated data properly updates six paths instead of appending six more.
Enable smooth pie transitions in d3 by using d3.attrTween and d3.interpolate to interpolate the arc start and end angles, managing previous data with a custom interpolator.
Implement the legend by creating a legend item container for each item, adding svg rectangles and labels, then repositioning the legend using symbol size, height, font size, and text separator.
Implement the set legend method by creating containers, adding legend items, symbols and labels, binding API data, and centering the legend using dimensions and margins.
Implement mouse enter, mouse leave, and click interactions on the legend to highlight the corresponding arc, fade others, and redraw the chart.
Define and wire legend mouse events, including enter, leave, and click, to toggle visibility by updating hidden IDs, filter pie arcs, and redraw the chart.
Enhance the pie chart styling by adjusting arc pad angle, corner radius, and inner radius, then apply stroke and stroke width to create a clean white border.
Improve arc transitions in interactive charts by refining the arcTween method to handle enabling and disabling edges, interpolating start and end angles, and maintaining smooth, sequential animations.
Learn how arcTween: enter animates new edges by binding previous and current data, extending previous data with the enter selection, and interpolating start and end angles for new elements.
Implement an exit arc tween in a D3 and Angular chart using a factory that swaps extended current and previous data for enter and exit transitions with 1000 ms duration.
Highlight arcs by mirroring the legend hover, pass mouse enter events from the legend container into the draw method with pie data, using data.id as the arc id.
Convert the chart configuration into an input, enabling two charts with distinct configurations (donut and pie), and implement a default and private config with deep copying to preserve styling.
We will create the method UpdateObjectWithPartialValues which allow us to set only some properties of an object, while keeping all the other properties unchanged
Outsource arc generator logic from the chart to the pie helpers, pass them as parameters, convert to static methods, and simplify the chart while keeping functionality.
Begin this project with a grouped and stacked bar chart, using the D3 group library, data structure design, tooltips, and reusable code.
Set up population data from the assets CSV, fetch it via a service, and expose it as an observable population$ in Angular to parse SVGs and the population CSV.
Create chart component with ng generate component, define input data and config, switch to string template with inline styling for svg class, and wire data into app component HTML.
Map API data to a multidimensional chart by structuring each element with year, gender, and age group, and convert incoming data to the domain, group, stack, and value format.
Learn to build interactive charts with d3 array by grouping and roll up data using group, groups, roll up, and flat roll up to sum by year, country, and gender.
Map each data element to domain, group, and stack using year, gender, age group, and value; define a unique key and build reusable helpers for flexible data transformation.
Define interfaces for group stack data and stack config, then use the stack helper to set stacks with population data by year, gender, and age group in millions.
Explore the anatomy of a d3 chart by structuring dimensions, margins, and inner dimensions with reusable helpers, then assemble axes, svg containers, legend, tooltip, and color scales.
Import three modules, add the svg, and initialize the chart using an element ref from angular core. Bind the host to d3.select(element.nativeElement) and initialize the svg on init.
Define chart structure by setting dimensions, elements, parameters, labels, axes, legend, and the draw method, with tooltip and highlight methods driven by events to update chart on init.
Define a default group stack config with opacity, transition, and margins, importing the correct interfaces. Implement a getter that returns the default when config is missing.
Setting a helper to calculate the most common points used in the chart
Create a short dimensions class to manage chart dimensions as a rect with margins, exposing getters for width, height, inner width, inner height, and base points (left, right, top, bottom).
Import short dimensions, define setDimensions with a new short dimensions from the dome rect and margins, and store the resulting dimensions as a global variable.
Implement the set elements by creating and positioning the x axis container, y axis container, data container, legend, tooltip, title, and y label, using margins and transforms.
Define setParams by configuring x domain as years, y from the max stack total, width and height ranges, group scale bandwidth, and colors with domain stack IDs using interpolate spectral.
Reorder charts by adjusting the app component HTML to place the pie chart on the left and the stacked bar chart on the right.
Implement the setparams method to initialize the x, y, group, and color scales, with each scale defined in its own method: setXScale, setYScale, setGroupScale, and setColorScale.
Define the x scale as a band scale with a discrete domain of unique, ascending group IDs and a range from zero to inner width.
Compute the y scale for stacked charts by aggregating per-group sums with flat rollups, determine min and max domains, then implement a linear inverted y scale with domain and range.
define the group scale with a scaleBand for the discrete domain of groups, set the range and bandwidth from the x scale, and then define the color scale.
For this lecture we will visit the d3-scale-chromatic github page to understand how to use the d3 color library
Learn to implement the set labels method by adding the chart title and y axis label, choose inline styling or css, and ensure svg export compatibility.
Bind the x axis to its container and apply its scale, bind the y axis similarly, and modularize with setXAxis and setYAxis.
Apply a value formatter to the stack helper to transform data into millions by dividing values by 1 million, enabling setStacks without breaking when data changes.
Guard against undefined data by initializing a default private underscore data object with guarded getters for the axis and scales; tune the y axis with ticks and inner tick size.
Explore d3 concepts for stacking data with d3.stack, drawing staggered rectangles by calculating stacked x positions and widths for each month across apples, bananas, cherries, and dates.
Learn to stack data with d3.stack in practice using a year-based dataset with apples, bananas, cherries, and dates, converting data to stack arrays and rendering rectangles with scales and colors.
Build stacked data by domain and group to visualize year and gender across domains, using stacks and scales to color each key and refine the data for correct ordering.
Learn how to implement a sorting facility for stacked charts by specifying stack order and stack IDs, adjusting the data (CSV) and legends with short names to fit the chart.
Add a legend to the chart by creating legend item containers with rectangles and labels, then add the rectangles and text elements and finally reposition the items.
Implement the set legend by creating item containers, binding stack order data, and drawing rectangles with centered labels, updating and repositioning items as data changes.
Explore tooltips in interactive charts by designing both svg and div tooltips, sizing and positioning them to convey the data message clearly with proper titles, units, and responsive resizing.
Explore building an svg tooltip template for interactive charts, including a title, symbol, and value, with a tooltip container, top-of-chart layering, and conflict-free class naming.
Define and implement a tooltip function for D3 charts, configure title, value, background, resize, and position, and attach it to mouse enter events on rectangles to display tooltips.
Learn how to simplify stacked data in D3 and Angular by using flatmap, min and max, and key-based filtering, while handling missing data with domain and group.
Refactor the drawRectangles method to render rectangles directly from a flat data array, replacing series containers with d.max and d.min bounds, adding color, and preparing the tooltip.
Define interfaces for tooltip data in interactive charts, map title, color, key, and value from stack data, and convert the tooltip to an arrow function for chart context.
Learn how to set up a tooltip in an interactive chart by binding tooltip data to title and value, fixing bugs, updating key and color, and preparing for positioning.
Set the tooltip position by converting events to SVG coordinates with three pointer, then update the tooltip container transform with the x and y values.
Configure tooltips by setting x and y padding, background color, and label properties like font size, height, and text separator to position and style svg tooltips.
Finalize the tooltip by calculating the svg tooltip dimensions, applying x and y padding, and styling the background with color, opacity, stroke, and a config font size.
Improve tooltip usability by implementing show and hide methods for the tooltip container with visibility styling, and address flickering by adjusting its positioning.
Improve tooltip movement by calculating position from a mouse event with an offset, using left-right placement and chart bounds to keep the tooltip inside.
Improve tooltip show and hide in D3 and Angular charts by updating on rectangle entry, moving with the svg, and hiding when leaving the svg area.
Highlight a rectangle in the chart by showing the tooltip and fading other rectangles, highlight the corresponding series on legend hover, and toggle series visibility by clicking legend items.
Highlight the corresponding series and legend items on legend hover in interactive D3 charts with Angular, updating highlights on mouse enter and reset on leave, and prepare for click events.
Toggle a legend item to hide or show a stack in the D3 and Angular chart by updating hidden IDs, filtering data, and redrawing the chart with the new stack.
Fix a bug by replacing appended text with select text in the update legend item. Highlight and fade disabled legend items using hidden IDs.
Improve bar transitions on toggle in an interactive D3 and Angular chart by adding enter transitions for new rectangles with zero height and millisecond durations for smooth visual cues.
Improve interactive charts by ensuring disabled elements do not highlight or fade others, and apply the same fade to legend labels and legend items.
Add a transition to the y scale and y axis so removal animates the chart, using the slow duration to match the short duration.
Improve the chart design by hiding tooltips when leaving the data container, add 20% inner padding and 15% group spacing, and adjust axes for clearer visuals.
Explore interactive charts with D3 and Angular by analyzing four data states—grouped, stacked, both, and neither—and adjust legends and stack options accordingly.
Add a grouped/stacked dropdown to update the stack data in the app component, using domain, group, and stack with year filtering to refine the population chart.
Fixes group and stack behavior in a short seven-component TypeScript file by detecting stacked vs grouped data, setting stack data, and adjusting color scales, tooltips, and legends.
Fix the tooltip and color mapping when no groups or stacks exist by adjusting the color domain, removing the legend, and using a sequential spectra scale.
Fix legend highlight for charts with groups and stacks by choosing stack data when available and otherwise using group data, ensuring accurate legend interactions in D3 and Angular.
Build an interactive map visualization using geojson data, projections, and path functions to render svg polygons across world layers, with tooltips and a covid-19 daily deaths timeline.
Generate the shards component shard eight, integrate D3, set up SVG, and define three inputs (geo data, data, config) and an output tooltip event to render a Covid data-driven map.
Set up two endpoints to fetch geojson and topojson data, explain features, geometries, and arcs, and compare 4326 (wgs84) projections and up to 80% space savings for efficient maps.
Add geo data via a countries geo data API to power an interactive D3 chart in an Angular app. Fetch json from assets, wire observables, and render geo arcs.
Combine a mega JSON file with iso-coded country data to feed an Angular D3 chart, binding via async pipes and a timeline for an interactive map visualization.
Combine two observables—covid by country data and country codes—from map countries.json using RxJS combineLatest to produce a single data stream, then subscribe and unsubscribe on destroy.
Create a map helper to convert covid data, including deaths, into map-ready format by mapping locations to iso3 codes and grouping data by date, with a title showing current date.
Define and refine map data interfaces, including iMap data elements and map config margins, for covid visuals. Implement set map data to update by date and track current date.
Set the dimensions on a dimension surface, define elements, parameters, labels, and legend, then draw the method and highlights using a non-linear scale and a map tooltip event emitter.
We are moving the DimensionHelper class into an angular service that can be injected into the charts
Set up and manage svg containers (country, data, title, legend) in a TypeScript file, then implement a positioning elements method to resize and reposition charts as dimensions change.
Set the map projection and path to convert polygons into an SVG path, then configure features and colors for the interactive charts, and next lesson explores projections.
Explore how map projections translate the globe onto a plane, compare equal-area, conformal, and equidistant types, and apply d3-geo-projection with equirectangular and mercator.
Convert GeoJSON features to svg paths with d3-geo projection, bind each feature to a path, and adjust scale, translate, center, rotate, and fit to render a world map.
Set the projection to d3 geo equirectangular, set the path, and set features to draw the map.
Convert topojson to geojson before applying D3 path generation by installing the topojson library and using topojson.feature to access geometry collections and their arcs.
Install topojson and import it into an angular chart; convert topojson to geojson with feature method and bind features to a path to render a map, addressing data loading timing.
Implement an update chart method that wires positioning, projection, path, features, labels, legend, draw, with guards for data and SVG readiness. Move and scale polygons to fit the map.
Explore d3.geoPath and d3.projection by examining default scale (152.63), default translate (480 by 250), and default center (0,0), then adjust scale and translate to see projections update.
Explore how d3.projection rotates the map using yaw, pitch, and roll by adjusting the rotate x, y, and z values.
Explore how to use d3.projection.fitSize to fit a map into a rectangle via fit extent and fit size, with width or height variants, using a geojson object and features.
Create a choropleth map by applying a scaled threshold with a discrete domain using the orange nine color scheme, and style polygons with dark gray strokes and white fills.
Split the map into multiple paths to color individual features. Bind data as features and apply per-feature styling with fill and white stroke, and adjust the fit extent and projection.
Set up a multi-layer map with a base layer and a data layer. Define a color scale with a domain of thresholds and the oranges scheme to color countries.
Draw data layers by filtering features using iso3 codes and binding to data features for the update chart. Use a color function to map values and gracefully handle nulls.
Set a single chart label from data.title and style it with svg attributes: text-anchor middle, font size 12, bold, dominant-baseline middle, and a 40 px top margin.
Bind threshold data to legend items, create and position legend item containers with rectangles and text, and wire mouse and click interactions.
Hovering a legend item highlights features sharing its color with a black stroke. The remaining features fade, and the active features bound to a threshold scale stay highlighted.
Highlight legend items and features on mouse enter, reset on mouse leave, using data-driven highlighting with a highlighted class and a black stroke for rectangles.
Implement legend highlights in a d3 and angular chart by color-based feature selection, converting colors to rgb with d3 color, applying highlight and faded styles, and adding reset for base layer and feature data.
Learn to implement interactive highlighting in a map built with D3 and Angular: highlight country feature and its legend item, show a tooltip on hover, then reset on mouse leave.
Set up show and hide tooltip functions and emit events, wire through map helper and app component to display tooltip data when entering a country and hide on leaving.
Learn how to implement a timeline tooltip in d3 and angular, covering required data (country title, time series, current date), tooltip positioning, show/hide logic, and coordinating map and helper components.
Define and emit map tooltip actions using a redux-inspired pattern to show and hide tooltips with iso3 country codes and x, y mouse positions.
Define map tooltip actions, set position, data, and visibility for showing tooltips, and reset position and visibility to hide tooltips in the map editor TypeScript file.
Develop the timeline tooltip and map tooltip components, use absolute positioning with left and top, and implement a tooltip state (visible, x, y) driven by the tooltip event payload.
Learn to build a timeline tooltip for interactive charts in Angular with D3, including an area and line, max value indicators, and an active date with axes and scales.
Set up a timeline tooltip component in Angular by configuring inputs, host access, SVG dimensions, and margins.
Define the interfaces for the timeline tooltip, including tooltip state, timeline data, and timeline config, with properties for visibility, position, title, active time, margins, dimensions, and typography.
Implement a timeline tooltip in a D3 and angular map by defining tooltip state, mapping country IDs to names, and wiring tooltip data to the map display.
Configure a timeline tooltip in D3 and Angular by defining the tooltip container, injecting the dimension service, and updating the chart when data changes with defined width, height, and styles.
Set up the SVG elements for the timeline tooltip, including title, axis and area/line paths, plus an active data container with a circle and labels, bound to map data.
Position svg elements for the timeline tooltip in the chart, using translate transforms, margins, and container dimensions, then ensure the tooltip is visible.
Fix the tooltip overflow by adjusting the app component: set the width to the max content and add a z-index of ten, removing overflow hidden from the short styling.
Set update chart parameters, labels, lines, and active data; compute the maximum value and active value from the current time, then configure scales and the area and line functions.
Set up x and y scales for the timeline chart with d3. Define the x domain from min to max date and the y domain from zero to max value.
Explore implementing d3 timeline visuals using setArea and setLine, defining y zero and y one with a date domain, and handling null values to skip drawing.
Define the setLabels method to initialize the timeline tooltip labels. Pull the title from the SVG and set the maximum value text.
Update the timeline tooltip styling by correcting position, applying the background color, and setting title and label typography—alignment, font size, weight, and anchor during the chart update.
Implement setLines to draw axis and max lines in a D3 and Angular timeline, defining x1, x2, y1, y2 with inner width and height, and applying stroke styles.
Draw the timeline line and area using drawLine and drawArea in a D3 and Angular chart, styling with rgb(253, 141, 60) stroke and 0.5 opacity for the area tooltip.
Update the timeline tooltip configuration by adding line stroke, area fill, and opacity, and extend the axis with color and optional dasharray for customizable tooltips.
Define an interactive timeline tooltip with active horizontal and vertical lines, a highlighted circle, and labeled active value and date, with configurable stroke, fill, radius, and decimals.
Adjust tooltip positioning in the map helper by tweaking coordinates (270px width, 150px height) to place the tooltip near the cursor, e.g., 125, with 20 pixels above the mouse.
Explore the slider component for a map, enabling date navigation from min to max with step and current value, plus play/pause and default speed; install bootstrap icons for Angular display.
Install the Bootstrap icons package, import its CSS in the angular.json styles array at the end, then serve the app to apply icons and proceed.
Install and add the play slider component to the app HTML before the map tooltip, and style the short body and controller for a 250-pixel height.
Build a play slider in Angular by adding min, max, step, and speed inputs, exposing value via getter and event emitter, and implementing play, pause, and toggle with html.
Create a play slider component with a play/pause toggle, a range input, and custom slider styling, wired to change events in an Angular D3 project.
Implement the play slider logic in TypeScript by starting an interval to advance values, emitting when below max, and providing pause, toggle, and value conversion from string to number.
Learn to implement a play slider controlling a covid map, configuring min, max, step (one day), and speed, and wiring data changes to update the map in real time.
Fixes the timeline tooltip by anchoring the date text to start on the left and to end on the right, ensuring the current date stays visible.
Update the map config to set title font weight and size, base fill and stroke, data label colors, and color schemes for d3 and angular maps.
Learn to resize charts by handling window resize events with a debounce time in RxJS, in an Angular and D3 setup, and manage subscriptions to implement the resize chart method.
Adjust chart dimensions, then reposition elements and set parameters, data, features, labels, legends, and draws, then resize and update the chart, testing with the map to verify correct resizing.
Enable strict mode, install d3 and topojson types, and update the config with required properties; then adjust code to fix typing errors and initialize variables in components.
Set up tsconfig and angular compiler options, install the type files for these three and topojson, and fix implicit typing and missing initializers when serving the app.
Adapt to strict mode and close the config. Initialize app component observables (population as an empty array, events as any, group tech data as empty object) before updating the charts.
Update the charts components in a strict Angular project by defining dom rects of 300 by 150, handling undefined values, typing with any, and refining D3 selections and tick formats.
Fix chart errors by updating the helpers, including map, object, pie, and stack, adjusting initializers and interfaces, and handling undefined data to finish the updates.
Define default margins, set the timeline domain to numbers, and fix app component errors to update the services, enabling the play slider and timeline tooltip.
Debug the application by tracing undefined config and data errors, define config as null for the default, and fix filtered and stacked data to restore maps and bar chart.
Fix the timeline tooltip error in the interactive charts with D3 and Angular by marking the max value as optional with a question mark, preventing undefined data from breaking computations.
The source code for the strict mode can be found here in the resources. However, You'll need to add the missing packages and change the tsconfig.json in order for the application to work.
Create a swarm chart from demographics data by continent and year using force simulation and Voronoi partitions, then build reusable base charts, legend and tooltip services, and optimize performance.
Define the component and interfaces for swarm config and ai swarm data, implement the dimension and tooltip services, and apply a force to circles with the d3 color scheme.
Create the short line component with inline template and style, skip tests, move the map within the app and insert the new chart, then explore the API and interfaces.
Implement an API to fetch demographics data and convert it to chart-ready format for interactive D3 and Angular charts, using demographics by year and country.csv.
Set up an Angular app component to fetch demographics from the API, subscribe to the demographics swarm observable, and convert data to the final format using a swarm helper.
Define interfaces for chart data, establish the swarm helper with data and set data methods. Assign five attributes: id, label, value, category, group to drive tooltips, year, and continent coloring.
Add and export the swarm helper class in the helpers folder, define its data object and set data attributes such as title, category, id, label, value, group, unit, and decimals.
Define and export interfaces for AI swarm data elements and the swarm data, including id, label, value, category, and group, plus title and unit fields.
Import ice form data from the sharp interfaces file, set empty title and unit, provide an empty data array, and finish implementing the set data method for the swarm helper.
Finish the setData method by converting an array of items into swarm data elements, including id, label, category, group, and value, with a configurable rounding function for decimals.
Set up a swarm helper in the app component, configure data mappings (title, category, id, label, value, group, units), and update it with converted data for the chart.
Design a reusable chart base for swarm charts by outlining common methods, inputs, and events; extend it to create specific charts with shared resize, update, and tooltip logic.
Create an abstract base chart in Angular by defining a non-instantiable class with inputs and outputs, d3 svg setup, host selection, typed data and config, and lifecycle hooks.
Extend the chart by subclassing the base chart into a swarm short component, wiring input data, config, and output events, and calling the superclass constructor to demonstrate inheritance.
Implement base chart configurations with margins and dimension services in an Angular D3 setup, define abstract default configs, and manage on set data and on set config across chart components.
Continue building the short chart component by handling init, resize, and chart updates with RxJS subscriptions, setting SVG, dimensions, and elements, then updating the chart on resize.
Select the SVG element from the host and apply the set SVG attributes, add more elements for a standards-based profile, and declare the type as SVGSVGElement to implement set dimensions.
Define base SVG dimensions from the node and update the surface with config margins, then set the viewBox; make set elements, set params, set labels, set legend, and draw abstract.
Implement all abstract methods in the bee swarm component to ensure it complies with the parent class and fix Topojson loading by initializing features to an empty array when undefined.
Set up the SVG chart elements for an interactive D3 and Angular chart, append the title and Y label, set up the axes and data containers, deferring legend and Voronoi.
Position chart elements by translating SVG groups for title, axes, and data using margins and midpoints. Set initial constants for the Y label offset and defer voronoi and legend.
Implement setParams by defining and invoking setGroups, setScales, setScaleData, setSimulatedData, and setAxis, establishing color groups, year-based x scale, and both axes.
Set groups for a D3 and Angular chart by using the group key as continent names and sorting alphabetically. Initialize data and map groups to arrays.
Explore defining x with a scale point, y with a linear scale from zero to inner width, and color with an ordinal scale by continent, then implement the scales.
Implement the set scales for x, y, and color using D3, define the x domain as years with a zero to inner width range, and adjust grouping by category.
Define a linear y scale with a domain (min to max) and a range from inner height to zero, using extent and accessors, while handling empty data and undefined values.
Define an ordinal color scale with a domain of groups and a range from the d3 tableau ten scheme, initialize with an empty array, and test with Asia.
Implement the first draw method by binding dot data to svg circles, setting cx, cy, radius, and color, then add margins and note future labeling.
Define margins to fit the axis, set up x and y axes, adjust scales and padding, remove last tick, apply grid lines with styled ticks, and refine for readable charts.
Explore the setLabels method to position and style chart labels in an svg—title and unit—rotating the unit by -90°, aligning with text anchor and dominant baseline, with font sizing.
Explore how the D3 force simulation models particle motion with constant time steps and mass, then apply horizontal, vertical, radial, and collision forces to nodes while using tick updates.
Define and apply scaled data for Type II swarm data elements by transforming data elements with x and y scales, preserving properties, and prepare to feed into the simulation.
Apply force simulation to scaled data, using force X, force Y, and force collide to move nodes toward target positions; visualize dynamics through ticks and adjustable strength.
Control the simulation with a tick loop and draw the chart each tick. Stop after 50 iterations and apply central attraction and collision forces to reveal distribution.
Define the interface for scaled data as a simulated swarm data element, extending Isam data elements, with psi, index, x, y, and horizontal and vertical velocity from force simulation.
Develop a reusable base legend service for D3 and Angular charts by extracting common legend components such as circle, text, and layout, and extending it for vertical and gradient legends.
Create and implement two legend services for a D3 and Angular chart: a base abstract legend service and a list legend service extended from a legend surface, both injectable.
Discover the abstract legend service for interactive charts with d3 and angular, defining data and config, and implementing generate, update, and set legend items with repositioning and highlighting.
Implement and adapt set legend items in an Angular D3 chart, creating a legend host on the chart surface and binding items with id, label, and color.
Define legend interfaces for the legend service, including a legend item with id, label, color, and a legend data list of items; set default data to an empty items array.
Generate and update legend items, then reposition the legend using a translate based on inner width and legend dimensions, with circles of radius three and text at font size twelve.
Update and reposition legend items in the chart by configuring padding and separators, supporting horizontal and vertical layouts, and using transform translate with bounding client rect for dynamic item placement.
Learn to implement an Angular legend service with an event emitter to handle mouse enter, mouse leave, and click actions for highlighting, hiding, or restoring legend items.
Learn hover highlighting for legend items across charts, applying font weight changes and emitting a legend item highlighted action using a Redux-style legend action pattern.
Subscribe to legend actions to handle legend item events in an interactive D3 and Angular chart, defining on-legend-action to log actions and update the last highlighted item.
Implement the click event in the legend to toggle visibility and styling of chart items, fading inactive items to 0.3 opacity and restoring them on re-click.
Highlight methods identify a group by id via the legend, fade other items with opacity, and reset highlights when the legend interaction ends.
Implement a legend item reset action in the legend service, optionally with a payload, and emit this action to clear highlighted items and reset the chart.
Learn to update a D3 and Angular chart by hiding points with legend interactions using hidden IDs, and adjust opacity to reflect hidden data.
Improve the legend by preventing disabled items from affecting the chart when hovering over Africa, using an id check for hidden groups to keep other points interactive.
Explore advanced legend interactions in interactive charts with D3 and Angular, including onMouseClick variations, selecting and toggling groups, and updating hidden items.
Implement hide all orders, reverse hidden, and the natural click behavior in the list legend service, using item ids and updating styles while emitting events.
Define the legend configuration object for the legend and list legend services, and establish a default config with item separator, circle radius, text and font sizes, opacity, and cursor.
Explore circle highlights in interactive charts by hovering over a circle to fade unrelated points, display a tooltip with the point information (Denmark, 1970), and highlight related time series.
Define and wire up on mouse enter and on mouse leave events for svg circles to highlight swarm data elements in an interactive d3 and angular chart.
Describe how to highlight corresponding circles on mouse enter, add a time series line, and set a tooltip, then reset by hiding all circles, removing the line and tooltip.
Append a time series line as an SVG path, hidden until a circle is highlighted; build it with x/y accessors, filter and sort by id and x, then bind datum.
Improve styling of interactive charts by applying a black stroke to highlighted elements and increasing their radius to three, while inactive ones stay at radius two.
Implement the tooltip service by reusing the chart's existing tooltip, wiring the template and host, and defining the interfaces, configuration, and styling needed for the tooltip.
Create a new tooltip service, export the class, decorate it with Angular core's injectable, and inject it via the constructor so it is available in the chart.
Move tooltip interfaces to a dedicated file and import tooltip data and config, then update components to use the new file so the chart works again.
Define the tooltip service data and config objects, import the selection, and implement set/get data and set/get config with default tooltip data and default tooltip config.
Bind the tooltip template to the host by defining the template, creating a tooltip container, and injecting the template into the host for a hidden tooltip.
Learners will implement the setTooltip function, assign tooltip data including year, category, color, country name, and value, and trigger showing the tooltip on the chart.
Learn to build and customize a tooltip service for D3 charts in Angular, using setElements to update data, styling via font size and weight, and accurately positioning the tooltip.
Learn to implement a tooltip positioning service in a D3 and Angular chart, computing x and y via the three-pointer method, translating the tooltip, and flipping sides to avoid clipping.
Adjust tooltip position by compensating for tooltip background padding with background x padding and background y padding, then apply config offset x to place it at the upper left corner.
Define X and Y tooltip positions as enums with left, middle, right and top, middle, bottom, and implement a default, partial position system via object helper in the tooltip service.
Define x and y padding using the tooltip dimensions to position the tooltip for left, middle, right and top, middle, bottom cases, then apply offsets.
Configure tooltip offsets to align with the circle position, applying horizontal offsets for left, right, and middle, and vertical adjustments for top and bottom.
Determine tooltip alignment in D3 and Angular interactive charts by comparing the x coordinate to the chart center and returning left or right positions.
Improve the tooltip behavior in the D3 and Angular chart by using pointer-events: none, delaying hide/show with transitions, and tuning durations to prevent flicker when moving between points.
Explore Delaunay triangulation and Voronoi partitions to simplify pointer navigation and tooltips in interactive charts. Learn to compute triangle circumcenters and map regions to circles for responsive highlighting.
Add a voronoi layer to the SVG as a container on top of the data, with class voronoi, and modify the draw method to call drawCircles and drawVoronoi.
Fix a legend onMouseClick bug by syncing legend clicks with item resets, updating highlights and IDs so Europe and Asia render immediately, then proceed with Voronoi development.
Implement Voronoi cells in a D3 chart by computing Delaunay and Voronoi partitions from scaled data, rendering region paths, and using mouse events to show tooltips.
Update the voronoi to reflect filtered data by removing hidden legend items and resetting the voronoi on legend clicks, drawing updated partitions for regions like North America and Europe.
Finish the swarm chart by adapting chart seven to the new tooltip service, implement the changes, and return after completing the update.
Injects the tooltip service into chart seven, imports and provides it, and updates tooltip visibility, position, and content using data title, key, and value for dynamic D3 and Angular charts.
Add an onMouseLeave handler in the draw rectangles method to reset highlights and apply a 300 millisecond opacity transition for smooth fading.
D3 is such a powerful language, however it can be difficult to start with.
Angular is an amazing framework but it lacks in data visualizations.
We will connect both worlds and create together amazing interactive charts that will bring your pages to another level.
For the absolute beginners, we will start from zero, understanding the d3 library, how it works, and how to use it. We will go into a depth analysis of the d3 update pattern so you can master the library and avoid the most common mistakes beginners do.
You will connect to api services and transform your data into the right format for each chart.
You will learn the SVG format and standards and how you can use it to create your own customized data visualizations.
We will use angular services and asynchronous data flows to inject data on the charts,
If you already know d3, you will learn about more advanced concepts, using the different d3 libraries, like the d3-array, the d3-force, voronoi partitions and others.
We will create legend and tooltip services, sending and receiving actions to charts and reacting to user inputs.
We will move into reusable charts by creating basic charts and extending them using inheritance.
Finally, you will end the course with a solid base to create your own reusable charts building upon the foundations of what you study here.
Welcome to the world of d3 and angular!