Using D3.JS, you can determine the minimum and maximum values within an array of arrays, a feature that is not

My data is structured as an array of arrays, with each inner array containing objects like this:

series = [ [ { "x":2013-01-01, "y":100 }, { "x":2013-01-02, "y":300 } ...],
           [ { "x":2013-01-01, "y":1000 }, { "x":2013-01-02, "y":300 } ...],...
         ]

I need to find the minimum and maximum values for both "x" and "y" using d3.js.

If I had a single array like this:

miniseries = [ { "x":2013-01-01, "y":100 }, { "x":2013-01-02, "y":300 } ...]

I could use a statement like this:

minX = d3.min(miniseries, function(d){return d.x});

However, I am unsure how to handle an array of arrays instead of just a single array.

Answer №1

Let's find the minimum x value in a series using D3 library:
var minX = d3.min(series, function (ms) {
    return d3.min(ms, function (d) {
        return d.y
    })
});

Answer №2

Simply loop through the data set and separate the values into two arrays (one for each axis). From there, you can easily determine the minimum and maximum values for both axes using the following approach:

To identify the minimum/maximum date (x-Axis):

// Example dataset
var dates = [ 
    new Date("2019-01-01"),
    new Date("2019-02-01"),
    new Date("2019-03-01")
];

var minDate = new Date(Math.min.apply(null, dates));
var maxDate = new Date(Math.max.apply(null, dates));

To discover the minimum/maximum value (y-Axis):

// Example dataset
var valuesAxisY = [200, 400, 600, 100];

var min = Math.min.apply(null, valuesAxisY),
var max = Math.max.apply(null, valuesAxisY);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Vibrant array of colors in AmCharts' line graphs

I'm looking to enhance my graph by having lines between the bullets in different colors based on their direction. For instance, if a line is rising (going from a bullet of smaller value to greater value), it should be green; if a line is falling, it s ...

Navigate to the editing page with Thymeleaf in the spring framework, where the model attribute is passed

My goal is to redirect the request to the edit page if the server response status is failed. The updated code below provides more clarity with changed variable names and IDs for security reasons. Controller: @Controller @RequestMapping("abc") public clas ...

Populating an array with a reference to the array

#include <stdio.h> #include <time.h> #define SIZE 20 #define MIN 0 #define MAX 100 void FillArray(int *array, int size); void PrintArray(int *array, int size); void BubbleSort(int *array, int size); void SelectionSort(int *array, int size); v ...

Storing the result of an Angular $http.get request in a variable

As a newcomer to Angular, I am exploring how to retrieve a JSON object containing a list of individuals from CouchDB using a $http.get call. The JSON structure includes an id, names, and quotes for each person: { "total_rows": 2, "offset": 0, ...

Mastering Fluent UI Web: Adjusting the border radius of a TextField component

I am in the process of creating a custom user input control that includes a TextField, a Dropdown, and a Button. To ensure that the TextField and Dropdown appear as a cohesive unit rather than two separate elements, I attempted to use two specific styles ...

Adjusting the size of a Vue component on the fly

I'm struggling to find a way to dynamically adjust the width of a component. The component I am working with is called 'vue-burger-menu' -> https://github.com/mbj36/vue-burger-menu. To set the width, you need to assign a number to the p ...

Unable to access MongoDB documents using NodeJS/Express

I can't seem to figure out why I am not receiving any results from a GET call I am testing with Postman. Let's take a look at my server.js file: const express = require("express"); const mongoose = require("mongoose"); const ...

Using jQuery to extract contact information from Google: A step-by-step guide

I'm currently using Google's API to access my contact list information and after logging the output in the console function fetch(token) { $.ajax({ url: "https://www.google.com/m8/feeds/contacts/default/full?access_token=" + token. ...

What is the trick to getting an accordion to expand when hovering, rather than when clicking?

Can the accordion be set to expand when hovering instead of clicking? Also, how can a different action be triggered on click? LATEST I was specifically referring to using the jQuery UI accordion widget for this functionality. ...

Leveraging the FileReader API within a Vue.js component function

I'm working on a Vue.js file picker that needs to display previews of selected files. To accomplish this, I am utilizing the FileReader API to read user-selected files as data URLs using the readAsDataURL method of the FileReader object. However, I&a ...

What is the best way to specifically target and style a component with CSS in a React application?

I'm facing a small issue with the React modals from Bootstrap in my application. In index.html, I include the following: <link rel="stylesheet" href="/assets/css/bootstrap.min.css"> <link rel="stylesheet" href=& ...

When using Browserify, the function require() on a concatenated string will not include the module in the output script

When using require() to create a combined string path, the path of the module will not be included in the output script. Examples of this include: require("./"+"b" ); //or var path="./"; require(path+"b"); Let's say we have a.js module.exports="a"; ...

When processing a series of input values, a C function executes successfully, but unexpectedly encounters a Segmentation Fault error with a value of

I am struggling to find a unique non-zero intersection between two sets. While my program works for some arrays, it encounters a segmentation fault for others. I have been attempting to identify the issue without success. Any assistance would be greatly ap ...

Ways to break apart a string of text without a regular pattern

Here is the data I am working with: Huawei Y7P Art-L28 (4/64gb) (AAAAAAAAAAAAAA) EXP:02/19/2020 Huawei Y9 prime 2019 (BBBBBBBBBBBBBBB) EXP:07/17/2019 Oppo A31 4gb/128gb (CCCCCCCCCCCCCCC) Vivo Y15 5000mah 4GB/64GB (1901) (DDDDDDDDDDDDDDD) EXP:06/14/2019 I ...

How can I replace specific text with HTML code in a webpage?

In my application, users have the ability to write comments that may contain HTML code. However, this code is escaped before being displayed: <div class="card-body"> <p class="card-text"> &lt;h1&gt;HOLA&lt;/h1&gt; Cita:#2&am ...

JavaScript Class vs Function as Definition

Having trouble locating documentation for this issue. I devised a JavaScript class in the following manner: class Polygon { constructor(height, width) { this.height = height; this.width = width; } area = function() { return this.height ...

Tips for delaying a node api's execution until a database query no longer returns null

While it may seem like an unnecessary complication, in my current scenario, it is exactly what I require. I am dealing with an API (API-1) that communicates with a third-party service. Instead of directly providing me with a response that I can send back ...

AngularJS routing not rendering the correct view

I'm encountering a routing problem with my AngularJS/ExpressJS application. The issue is that login.ejs and signup.ejs are partial views, while welcome.ejs serves as the main template. The intention is for these views to load in a ui-view container wi ...

What is the best way to incorporate audio in my node.js messaging platform?

I've spent all day trying to figure out how to play sound using node.js. Unfortunately, I can't use "document.getElementById" or "new Audio". My goal is to have a sound play whenever I type "@everyone" in my chatroom. The audio file is named "pin ...

Is it possible for two distinct devices to generate the same HWID using Pushwoosh Cordova API?

Our app relies on HWIDs generated by Pushwoosh to distinguish between devices. After reviewing traffic logs, I noticed a peculiar pattern of what appears to be the same device sending HTTP requests from various ISPs within short time intervals. It seems t ...