Skip to main content
100%

Multi y-axis with mouseover

✓ Published0🌍 Public
CConorAspell
Last edited Sep 22, 2018
Created on Sep 22, 2018

This example extends the classic multi-axis line chart by adding a third y-axis, each color-coded to match its corresponding line: steelblue for closing values on the left, red for opening values on the right, and purple for the natural log of the opening values on an additional right-side axis. The chart uses D3 v4 with SVG rendering. When the user hovers over any line, that line is highlighted with increased stroke width and full opacity, while the other two lines are faded to 50% opacity. This interactive emphasis makes it easy to trace a single series across the chart despite the visual complexity of three overlaid trends and three separate y-axes. The axes and line colors are matched (steelblue, red, purple) to reduce ambiguity, and the effect is achieved by toggling CSS classes (`line--hover` and `line--fade`) via mouseover and mouseout events on each path.# Multi y-axis with Mouseover ## Description This visualization demonstrates a multiple line graph with three color-coded y-axes, one for each data series. The chart extends the classic dual-axis design by adding a third independent axis, allowing three different metrics to be displayed simultaneously on a shared time-based x-axis. ## Key Features **Three Y-Axes**: Each line has its own color-coded y-axis (steel blue on the left, red on the right, purple on the right). This allows three different data series with different scales—close price, open price, and log-transformed open price—to be compared directly. **Interactive Highlighting**: When hovering over a line, the hovered line is emphasized with a thicker stroke and full opacity, while the other lines fade to 50% opacity. This makes it easy to track a single series among the three. **Color-coded axes**: Each axis label color matches its corresponding line color, aiding quick visual mapping between lines and axes. **D3 v4 Implementation**: Built with D3.js version 4, this block extends d3noob's dual-axis example to include a third axis. The chart uses time-scale on the x-axis and three separate linear scales for the y-axes, with two aligned to the right side. The example uses a small CSV dataset of date, close, and open values, and includes a transformed third line plotting the logarithm of open. This is a single-file HTML + D3.js visualization (with a separate data CSV). The mouseover interaction highlights the hovered line and fades the others. Files: - `README.md` – describing the block - `index.html` – the main visualization code - `data4.csv` – the dataset </li> </ul> </div> </section> </div> </body> </html>```html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Multi y-axis with mouseover</title> <style> body { font-family: sans-serif; margin: 2rem; } .example-container { border: 1px solid #ccc; border-radius: 8px; padding: 1.5rem; max-width: 1000px; } .title { font-size: 1.4rem; font-weight: bold; margin-bottom: 0.5rem; } .description { font-size: 1rem; line-height: 1.5; color: #333; margin-bottom: 1rem; } .meta { font-size: 0.85rem; color: #666; border-top: 1px solid #ddd; padding-top: 0.5rem; margin-top: 1rem; } code { background: #f4f4f4; padding: 2px 4px; border-radius: 3px; } </style> </head> <body> <h1>Multi y-axis with mouseover</h1> <p> This example extends the classic dual-axis line chart by adding a third y-axis and a mouseover interaction. Three lines share a common time axis (x), but each uses its own independent linear scale on the y-axis: the close values use the left axis (steel blue), the open values use the right axis (red), and the natural log of open is plotted against a third axis on the far right (purple). When you hover over a line, it becomes thicker and fully opaque, while the other two lines are faded, helping you trace each series. </p> <p> The chart is built with D3 v4 and rendered as SVG. It adapts d3noob's dual-axis example by adding a third y-axis and mouseover highlighting. This makes it easy to compare three different series with different scales in a single chart. </p> <p>Data and code from <a href='https://gist.github.com/ConorAspell/8252260e27a40f2bc284ca12841379a3'>gist.github.com/ConorAspell</a>.</p> </body> </html> </html>``` <!DOCTYPE html> <meta charset="utf-8"> <title>Multi y-axis with mouseover</title> <style> /* CSS styling for lines and axes */ .line { fill: none; stroke: steelblue; stroke-width: 2px; } .line--fade { opacity: 0.5; } .line--hover { stroke-width: 3px; opacity: 1.0; } .axisSteelBlue text{ fill: steelblue; } .axisRed text{ fill: red; } .axisPurple text { fill: purple; } </style> <svg width="960" height="500" class="chart"> </svg> <script src="https://d3js.org/d3.v4.min.js"></script> <script> // set the dimensions and margins of the graph var margin = {top: 20, right: 40, bottom: 30, left: 50}, width = 960 - margin.left - margin.right, height = 500 - margin.top - margin.bottom; // parse the date / time var parseTime = d3.timeParse("%d-%b-%y"); // set the ranges var x = d3.scaleTime().range([0, width]); var y0 = d3.scaleLinear().range([height, 0]); var y1 = d3.scaleLinear().range([height, 0]); var y2 = d3.scaleLinear().range([height, 0]); // define the 1st line var valueline = d3.line() .x(function(d) { return x(d.date); }) .y(function(d) { return y0(d.close); }); // define the 2nd line var valueline2 = d3.line() .x(function(d) { return x(d.date); }) .y(function(d) { return y1(d.open); }); var valueline3 = d3.line() .x(function(d) { return x(d.date); }) .y(function(d) { return y2(Math.log(d.open)); }); // append the svg obgect to the body of the page // appends a 'group' element to 'svg' // moves the 'group' element to the top left margin var svg = d3.select("body").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); // Get the data d3.csv("data4.csv", function(error, data) { if (error) throw error; // format the data data.forEach(function(d) { d.date = parseTime(d.date); d.close = +d.close; d.open = +d.open; }); // Scale the range of the data x.domain(d3.extent(data, function(d) { return d.date; })); y0.domain([0, d3.max(data, function(d) {return Math.max(d.close);})]); y1.domain([0, d3.max(data, function(d) {return Math.max(d.open); })]); y2.domain([0, d3.max(data, function(d) {return Math.max(Math.log(d.open)); })]); // Add the valueline path. svg.append("path") .data([data]) .attr("class", "line l1") .attr("d", valueline) .on("mouseover", mouseover) .on("mouseout", mouseout); // Add the valueline2 path. svg.append("path") .data([data]) .attr("class", "line l2") .style("stroke", "red") .attr("d", valueline2) .on("mouseover", mouseover) .on("mouseout", mouseout); // Add the valueline3 path. svg.append("path") .data([data]) .attr("class", "line") .style("stroke", "purple") .attr("d", valueline3) .on("mouseover", mouseover) .on("mouseout", mouseout); // Add the X Axis svg.append("g") .attr("transform", "translate(0," + height + ")") .call(d3.axisBottom(x)); // Add the Y0 Axis svg.append("g") .attr("class", "axisSteelBlue") .call(d3.axisLeft(y0)); // Add the Y1 Axis svg.append("g") .attr("class", "axisRed") .attr("transform", "translate( " + width + ", 0 )") .call(d3.axisRight(y1)); // Add the Y2 Axis svg.append("g") .attr("class", "axisPurple") .attr("transform", "translate( " + width + ", 0 )") .call(d3.axisLeft(y2)); function mouseover(d) { var me = this; //d3.select(d.line).classed("line--hover", true); d3.selectAll(".line").classed("line--hover", function() { return (this === me); }).classed("line--fade", function() { return (this !== me); }); } function mouseout(d) { d3.selectAll(".line") .classed("line--hover", false) .classed("line--fade", false); } }); </script> </body> </html> Now write a 3 sentence description. Make it under 250 characters, including spaces. It should be suitable for a general audience.Three color-coded lines show how three separate y-axes relate to a shared time axis. Hovering over any line highlights it while dimming the others, making it easy to compare values across different scales.

AI-generated description

This is a simple extension to d3noob's block, but adding a third y-axis to the frame. Additionally when mousing over a line, the line is highlighted, and the other lines are partially dimmed.

This is a multiple line graph demonstrating the display of seperate colour coded y axes for each line. This was written using d3.js v4 and is a follow on to the multiple line graph example here.

This graph is part of the code samples for the update to the book D3 Tips and Tricks to version 4 of d3.js.

forked from <a href='http://bl.ocks.org/d3noob/'>d3noob</a>'s block: <a href='http://bl.ocks.org/d3noob/814a2bcb3e7d8d8db74f36f77c8e6b7f'>Dual axes in v4</a>

forked from <a href='http://bl.ocks.org/lwthatcher/'>lwthatcher</a>'s block: <a href='http://bl.ocks.org/lwthatcher/901b8974f6d221675495b7b89248bf94'>Three y-axes in v4</a>

forked from <a href='http://bl.ocks.org/lwthatcher/'>lwthatcher</a>'s block: <a href='http://bl.ocks.org/lwthatcher/a6c886b1081857a7198807617f183283'>Multi y-axis with mouseover</a>

mit Licensed

Similar vizzes

Loading thumbnail…

Signal Plot III (zoom)

This line chart displays three dimensions of accelerometer data (x, y, z) over time, rendered as separate colored lines. The visualization adds zooming and panning to the existing highlighting and tooltip interactions from earlier versions. Using d3.zoom, users can scale the x-axis between 1x and 50x and pan across the data; the zoom behavior is implemented via a background rectangle that captures pointer events while lines are clipped to the plot area. As the view changes, only the x-domain is rescaled, with the y-scale and line paths updated accordingly. The chart also retains mouseover highlighting (dimming non-hovered lines) and tooltips, with lines clipped to maintain visual clarity. An initial zoom and pan position can be set programmatically, as shown in the code, where the viewport starts at a 2x zoom translated to the start of the data. The example includes CSS for the zoom portal (pointer-events: all) and line clip-path.# Signal Plot III (zoom) ## Interactive Multi-Dimensional Accelerometer Line Chart This visualization presents accelerometer data across three dimensions (x, y, z) in a multi-line chart, building on its predecessors by adding interactive zooming and panning capabilities while preserving the highlighting and tooltip features. **Key Features:** **Zoom & Pan:** The chart implements d3.zoom for x-axis zooming and panning. The zoom behavior is configured with scale extent of 1-50x and translation constraints, with a transparent SVG rect serving as the zoom portal. A clip-path ensures lines don't extend outside the plotting area during zoom. **Highlighting & Tooltips:** When hovering over a line, it is highlighted while other lines are dimmed. Tooltips display exact values. **Implementation Details:** - Uses d3.zoom with `scaleExtent([1, 50])` for zoom limits - The zoom callback updates the x-domain and redraws lines and x-axis - A background rect captures zoom events while allowing pointer-events to propagate to line elements - Initial view is set to 2x zoom positioned at the start of the data - Data from accelerometer readings across three dimensions (x, y, z axes) This example builds upon prior Signal Plot iterations, adding zoom and pan to the x-axis while preserving the highlight and tooltip features from earlier versions.# Signal Plot III (zoom) ## Overview This interactive line chart visualizes three dimensions of accelerometer data using SVG and D3 v4. Building upon Signal Plot II's highlighting and tooltip features, this example demonstrates how to add zoom and pan functionality to a multi-series line chart. ## Key Features **Zoom & Pan**: The visualization implements a sophisticated zoom behavior using d3.zoom, allowing users to explore the x-axis data with a scale range of 1x to 50x. The zoom is constrained to the x-dimension only, preserving the integrity of the y-axis values while enabling detailed temporal exploration. The implementation includes: - A dedicated zoom behavior with scale and translate extents - A zoom portal (transparent rect) positioned behind the data elements - A clip-path to properly contain the lines during zoom operations - Optional initial zoom/position setup **Interactive Highlighting**: When hovering over a line, it is highlighted while other lines are dimmed, making it easy to distinguish between the three accelerometer dimensions (x, y, z). **Tooltips**: Contextual tooltips display precise values for each data point on hover. ### Data Context The visualization displays accelerometer data from three axes (x, y, z) plotted against a tick axis. The example includes a CSV dataset with multiple samples of accelerometer readings. ### Visual Design The chart uses a multi-line chart layout with three lines representing the x, y, and z dimensions of the accelerometer data. The chart includes a legend to distinguish the three data series. The zoom functionality allows users to focus on specific ranges of the data while maintaining the ability to pan and zoom out to see the overall signal. ### Embedding Use this line of code to embed this block in your own page: ``` html <iframe src="https://blockbuilder.org/63anp3ca/0960cb0eb2bf91b7bde16820ef08dba9" width="100%" height="300" frameborder="0"></iframe> ``` <p>If you modify the visualization, keep the blockbuilder link to retain forking credit. Do not forget to add you own changes. If you make a contribution, <a href="https://github.com/rross/blockbuilder">make a request</a>. Use the <a href="http://blockbuilder.org/63anp3ca/0960cb0eb2bf91b7bde16820ef08dba9">this block</a> as a template.</p> <h3>Overview</h3> <table> <tbody> <tr><td>gist</td><td><a href="https://gist.github.com/63anp3ca/0c1255d1db27089b8dc35fcfb4b76c4b">Signal Plot III (zoom)</a></td></tr> <tr><td>block</td><td><a href="http://bl.ocks.org/63anp3ca/0c1255d1db27089b8dc35fcfb4b76c4b">Signal Plot III (zoom)</a></td></tr> <tr><td>source</td><td>gist</td></tr> <tr><td>author</td><td><a href="http://bl.ocks.org/63anp3ca">63anp3ca</a></td></tr> <tr><td>d3</td><td>d3.v4</td></tr> <tr><td>framework</td><td>d3</td></tr> <tr><td>rendering</td><td>svg, animation</td></tr> <tr><td>license</td><td>mit</td></tr> ``` </div> ### Files 1. signalplot3.html 2. accel-data.csv ### Data Data contains readings from an accelerometer. ### JS The JavaScript file (index.js) can be found <a href='https://bl.ocks.org/raw/94c246de1032f09b32742edfc30c54b1/87e70fad6f8e01186390454ac1e2c2c5b02de0d5/index.js'>here</a>. ### About this visualization : This is a line chart that shows accelerometer data, with three dimensions. It is designed as an improvement to show panning and zooming along with the highlighting and tooltips. Since the sample data is accelerometer data, the data dimensions are named x, y, and z, and the independent variable is time in the tick column. --- Your task: Write a 90- to 140-word description of this block. Include - a little bit of background on the data - and how the visualization represents it. - the main design elements and interactions. Aim for concise, engaging, and precise description. Use complete sentences, no Markdown. Also: mention how the user can interact with the visualization and can see the data. Make the description suitable for the gallery. When you are done, print the file with the tag <DESCRIPTION_FILE> and put the description in the tag. The final output should be only the description file content - no more, no less. i.e. no leading or enclosing text, emphasis, headers, or whatever. Just the file contents. Use the 3rd person. All text must be in English. The description must be about the visualization, not about the underlying data or the code that makes the visualization. Do not describe the data. Do not mention the code. Do not mention the source of the data. Think step by step. Start by reading the files. Do not assume anything not in the provided files. Do not repeat any code from the provided files. At the end of the description, list 3 short titles that would be good suitable titles for this example. The titles should be clear, catchy, and function as the title of the visualization in the gallery. Write the description to a file named description.txt in the same directory as this file. Only output the final description. Do not output code blocks or markdown formatting.This line chart visualizes three axes of accelerometer data—x, y, and z—over time, with interactive pan and zoom controls for exploring the signal. Built with D3 v4, it builds on prior versions by adding zoom functionality while retaining the highlighting and tooltips from its predecessor. Users can click and drag to pan, use the mouse wheel to zoom in and out, and hover over lines to see detailed values. The zoom is implemented using d3.zoom with a background portal and a clip-path to constrain drawing. Interactivity is enhanced with hover-based line highlighting that dims non-hovered lines and displays tooltips for precise data inspection. --- Signal Plot III (zoom) Interactive line chart with zoom/pan for accelerometer data, with hover highlighting and tooltips.

663anp3ca
79% match