Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8973941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:33:50+00:00 2026-06-15T18:33:50+00:00

I give up, I can’t figure it out. I was trying to create a

  • 0

I give up, I can’t figure it out.
I was trying to create a bar chart with 3d.js but I can’t get it working. Probably I don’t understand it enough to deal with my complicate associative array.

My array has the following structure:

{"January"=>{"fail"=>13, "success"=>6},  
 "February"=>{"success"=>10, "fail"=>4},  
 "March"=>{"success"=>9, "fail"=>13},  
 "April"=>{"success"=>16, "fail"=>5},   
 "May"=>{"fail"=>52, "success"=>23},   
 "June"=>{"fail"=>7, "success"=>2},   
 "July"=>{},  
 "August"=>{"fail"=>6, "success"=>3},  
 "September"=>{"success"=>54, "fail"=>59},   
 "October"=>{"success"=>48, "fail"=>78},  
 "November"=>{"fail"=>4, "success"=>6},  
 "December"=>{"fail"=>1, "success"=>0}}`

I got the displaying of the axis working:
enter image description here

The code looks really ugly because I converted the names to a “normal” array:

monthsNames = new Array();
i = 0;
for (key in data) {
  monthsNames[i] = key;
  i++;
}

x.domain(monthsNames);
y.domain([0, 100]); 

But I can’t figure it out how to deal with the data.

I tried things like, svg.selectAll(".bar").data(d3.entries(data))
What is a good beginning I guess but I can’t get the connection to the axis working.

What I want to create is a bar-chart that has the months as x-axis and every month has two bars (respectively one bar with two colours) – one for success and one for fail.

Can anybody please help me how to handle the data? Thanks in advance!

EDIT:

I cannot figure out how to scale x and y. If I use this code:

var x = d3.scale.ordinal()
   .domain(monthsNames)
   .range([0, width]);

var y = d3.scale.linear()
   .domain([0,100])
   .range([0, height]);

nothing is shown up then. If I print out the values that evaluate after using e.g. x(d.key) or x(d.value.fail) they are really strange numbers, sometimes even NaN.

EDIT:

d3.selectAll(".barsuccess")
      .on('mouseover', function(d){
                    svg.append('text')
                    .attr("x", x(d.key))
                    .attr("y", y(d.value.success))
                    .text(d.value.success+"%")
                    .attr('class','success')
                    .style("font-size","0.7em")
                })
                .on('mouseout', function(d){
                    d3.selectAll(".success").remove()
                });  


d3.selectAll(".barfail")
          .on('mouseover', function(d){
                        svg.append('text')
                        .attr("x", x(d.key)+x.rangeBand()/2)
                        .attr("y", y(d.value.fail))
                        .text(d.value.fail+"%")
                        .attr('class','fail')
                        .style("font-size","0.7em")
                    })
                    .on('mouseout', function(d){
                        d3.selectAll(".fail").remove()
                    });  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:33:52+00:00Added an answer on June 15, 2026 at 6:33 pm

    Be sure to check out the bar chart tutorials here and here. You have basically all you need already. The connection between the axes and the data are the functions that map input values (e.g. “March”) to output coordinates (e.g. 125). You (presumably) created these functions using d3.scale.*. Now all you need to do is use the same functions to map your data to coordinates in the SVG.

    The basic structure of the code you need to add looks like

    svg.selectAll(".barfail").data(d3.entries(data))
       .enter().append("rect")
       .attr("class", "barfail")
       .attr("x", function(d) { x(d.key) })
       .attr("width", 10)
       .attr("y", function(d) { y(d.value.fail) })
       .attr("height", function(d) { y(d.value.fail) });
    

    and similar for success. If you use the same scale for the x axis for both types of bar, add a constant offset to one of them so the bars don’t overlap. Colours etc can be set in the CSS classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You can give someone an url with get: http://myserver.com/?var=val But what to do with
Someone can give me short explanation how to create bitmap runtime using GDI/GDI+ and
Anyone can give me an example on how to create local data caching? Like
I can give it floating point numbers, such as time.sleep(0.5) but how accurate is
I hope someone can give me a hand figuring this out. I have been
Anyone can give me a working sample of JSF2.0 + richfaces4.0? I just upgrade
Hoping someone can give me some pointers. I'm trying to add a 'pulsate' effect
Maybe someone can give me a hint, how to create non-scaleable textareas? I tryed
I'm hoping someone here can give me some guidance. I'm working on a project
is there anyone who can give me a vital and simple explanation im trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.