D3 and Select struggling to conform to HTML layout

I've been putting in a lot of effort working with D3 to align my HTML layout, but I'm struggling to get my charts to align as desired.

What I'm aiming for is:

              BAR CHART

1st PIE CHART, 2nd PIE CHART, FIELDSET

So, what I need to do is switch the position of the second Pie Chart with the "Options" fieldset.

Here's what I've attempted so far:

var svg = d3.select("#divs").append("div").attr("id","svg-cont")
                .style("margin-top", 50)//.style("margin-left", 405)
                .append("svg").attr("width", 210).attr("height", 200);

      svg.append("g").attr("id","salesDonut");

      var data = [10,20,30,40,50,60];
      var data1 = [0,10,20,30,40,50,60,70,80,90];

      if(d3.select('#opt-fieldset').empty()){
          var fieldset = d3.select("#svg-cont").append("fieldset").attr("id","opt-fieldset").style("float","left").style("width",150)
                        .html('<legend>Options</legend>\
                          <d>Rotation: </d>&nbsp;&nbsp;&nbsp;\
                          <select id="rotation" style="position: right;">\
                          </select>  &nbsp; \
                          <br><d>Inclination: &nbsp;</d>\
                          <select id="inclination" style="position: right;">\
                          </select>'); 

            var rotate = d3.select("#rotation");
                rotate.selectAll("option").data(data).enter().append("option")
                        .attr("value", function (d) { return d; })
                        .text(function (d) { return d; });

            var inclinate = d3.select("#inclination");
                inclinate.selectAll("option").data(data1).enter().append("option")
                        .attr("value", function (d) { return d; })
                        .text(function (d) { return d; });
      }else{
        console.log("Godspeed");
      }

      Donut3D.draw("salesDonut", getData(data3D),
          marginLeft, marginTop, pieWidth, inclination, pieThickness, pieHole);

For the complete code and result in Plucker, check out (Click on any bar to display the 2 pie charts and the fieldset).

Answer №1

Instead of aligning your fieldset to the left, consider aligning it to the right. In my opinion, your current HTML structure is a bit messy because the three elements you want to align at the bottom are attached to different parent divs, making styling a bit tricky. I would recommend the following approach:

Place both pie charts and the fieldset inside the same div container and then style them using CSS.

// Add the second pie chart to #div1 where you already have the first one
var svg = d3.select("#div1").append("div").attr("id","svg-cont")
                .style("margin-top", 50)//.style("margin-left", 405)
                .append("svg").attr("width", 210).attr("height", 200);

// Append the fieldset to #div1, which already contains the two pie charts
var fieldset = d3.select("#div1")
                 // Add another div here to wrap the fieldset
                 .append('div')
                 .append("fieldset")
                 // Remove float: left
                 .attr("id","opt-fieldset").style("width",150)
                 .html('<legend>Options</legend>\
                          <d>Rotation: </d>&nbsp;&nbsp;&nbsp;\
                          <select id="rotation" style="position: right;">\
                          </select>  &nbsp; \
                          <br><d>Inclination: &nbsp;</d>\
                          <select id="inclination" style="position: right;">\
                          </select>'); 

// Remove float: left from #div1 in your HTML
<div id="div1"></div>

// Finally, use the following styles to align the 3 elements
#div1 > div {
     display: inline-block;
     vertical-align: middle;
}

Check out a DEMO based on your code.

Answer №2

To achieve the desired css for the fieldset style, you can utilize the following code snippet: .style("float","right")

Here is an example of how to implement it:

var fieldset = d3.select("#svg-container").append("fieldset").attr("id","option-fieldset").style("float","right").style("width",150)
                            .html('<legend>Options</legend>\
                              <d>Rotation: </d>&nbsp;&nbsp;&nbsp;\
                              <select id="rotation" style="position: right;">\
                              </select>  &nbsp; \
                              <br><d>Inclination: &nbsp;</d>\
                              <select id="inclination" style="position: right;">\
                              </select>'); 

For a live demonstration of the code, you can visit this link

I hope this information proves to be useful for you!

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

Understanding the functionality of a notification system

Planning to create an admin tasking system utilizing PHP, MySQL, and JavaScript. Curious about how the notification system operates and how it stores real-time data. Are there any good examples of a notification system? ...

Looking to extract the hidden value from an HTML input field using Selenium

Unable to retrieve the value of a hidden element in HTML, even though it is displaying. Seeking assistance in accessing the value despite the type being hidden. <input type="HIDDEN" label_value="Sub Reference" title="Sub Reference" id="ACC_NO" dbt="BK_ ...

The Javascript executor in Selenium is delivering a null value

My JavaScript code is causing some issues when executed with Selenium's JavascriptExecutor. Strangely, the code returns null through Selenium but a value in Firefox developer console. function temp(){ var attribute = jQuery(jQuery("[name='q& ...

Choose a select few checkboxes and then disable the remaining checkboxes using Vue and Laravel

I'm currently working on a project using Laravel 10 and Vue3. In the form, users are allowed to select only 3 checkboxes. Once they have selected 3 checkboxes, all remaining checkboxes should be disabled. I attempted to implement this functionality a ...

Bizarre symbols observed while extracting data from HTML tables produced by Javascript

I am in the process of extracting data from Specifically, my focus is on the "tournament-page-data-results" div within the source code. Upon inspecting the HTML source code, the data does show up, but it appears with a mix of real information and random c ...

Is it recommended to use Promise.await over async/await?

After starting some new operations in my project, I discovered that db.aggregate needed to be executed asynchronously: db.aggregate( [ { $match: { "records": { $e ...

Gather numerical values and transform them into dates using AngularJS

My Angularjs project involves 3 scopes for year, month, and day which are retrieved from 3 input boxes. I need to combine them into a date, but the current code inserts the date with an additional 22:00:00 like 2019-06-01 22:00:00.000. How can I insert the ...

Steps for transforming an array of arrays into a JSX element within a React component, where each nested array contains its own clipPath

The array_groups variable consists of an array containing multiple arrays. Each inner array holds the coordinates of regular circles that are closely spaced together. The intention is to clipPath these inner circle arrays as a whole. When the mouse hovers ...

Vue.js - I am looking to create dynamic buttons that change color when clicked

I have dynamically created buttons using v-for and now I want the clicked button to change color while the others remain the same. <template> <div id="exam-screen" class="exam jumbotron"> <h1>{{ title }}</h1> <div cl ...

Camera Capacitor designed to eliminate popup notifications

I am utilizing Angular along with the camera plugin in Capacitor to locally save images on both desktop and tablets. I aim to utilize the CameraSource to directly access the camera or open the gallery for files without displaying a prompt. This is how my ...

Selenium web driver showcases its capability by successfully launching the Firefox browser, yet encounters an issue with an invalid address

WebElement searchElement = driver.findElement(By.name("q")); searchElement.sendKeys("Selenium WebDriver"); searchElement.submit(); Displays "Search Results" public static void main(String[] args) { // TODO Auto-generated method st ...

Encountering an error message that states "Unable to access property 'props' of null object while filling

Can anyone help me figure out the error in my React component code below? import React, { Component } from 'react'; import { Input} from 'antd'; import Form from '../../components/uielements/form'; import Button from '.. ...

Troubleshooting a malfunctioning filter in Moongose for a Referenced Entity

I am dealing with two main Entities called Organization and Applications. A single organization has the capability to possess multiple Applications. const organization = mongoose.Schema( { name: { type: String, required: ...

Determine with jQuery whether the img src attribute is null

My HTML structure is as follows: <div class="previewWrapper" id="thumbPreview3"> <div class="previewContainer"> <img src="" class="photoPreview" data-width="" data-height=""><span>3</span> </div> </div> ...

Exploring Ways to Retrieve Depth Information within three.js

I have come across shaders that can dynamically create outlines around edges based on the difference in depth of pixels. This means that pixels with less depth compared to their adjacent pixels might have a thinner outline or none at all. Examples of such ...

Tips for adding a new value to an array of objects in React

As I navigate my way through the world of React as a newcomer, I've encountered a challenge that I need some advice on. I am attempting to add a new key and value to an array of objects, but I'm struggling to accomplish this task. Can anyone prov ...

Arranging the table based on the values of the key

I have already discovered that using the sort function is necessary to sort the table onClick. My goal is to sort by the key so that I can avoid repeating the code to sort the function by key. I am trying to keep my code DRY. How can I achieve this efficie ...

When json.parse encounters an undefined value at position 1

Currently, I am diving into learning express.js and my latest project involves creating a web app that can convert cryptocurrency to Fiat currency. Things have been progressing smoothly so far, but I've hit a roadblock when attempting to use json.pars ...

Identify duplicate values in an array by comparing pairs of elements

If the array contains the data shown below: let array = [{ name: "Ramesh", SalseVersion: 10, MarketingCode: 11 }, { name: "Suresh", SalseVersion: 12, MarketingCode: 13 }, { name: "Siva", SalseVersion: 10, MarketingCode: 14 }, { na ...

Creating a custom comparison method between two select dropdowns using the jQuery Validation plugin

In my HTML code, I have two select elements: <label for="h_slat_type">Horizontal Slat Type</label> <select name="h_slat_type" id="h_slat_type"> <option disabled="disabled" selected>Select</option> ...