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

  • Home
  • SEARCH
  • 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 8255709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:37:09+00:00 2026-06-08T01:37:09+00:00

This is a chart that I have made using d3.js. I want my bars

  • 0

Vertical/Column Bar Graph
This is a chart that I have made using d3.js. I want my bars to be centered around the tick values – as in the middle bar of each set (of 3 bars) should coincide with the month name. Is there some way to do this elegantly? Do let me know if you need more info on the data set or the chart functions.

Some helpful code

this.container.selectAll('g.container')
    .data(this.data)
  .enter().append('g')
    .attr('class', 'container')
    .attr('transform', function(d, i){
        console.log(d.dimension, this)
        var x = self.margin.left + self.xScale(d.dimension.value);
        var y = self.margin.top;
        return 'translate('+ x + ',' + y +')'
});

this.bars = this.container.selectAll('g.container')
    .selectAll('rect.bar')
    .data(function(d){ return d; })
  .enter()
    .append('rect')
    .attr('class', 'bar')
    .attr('width', 3)
    .attr('height', function(d){
        console.log(d.y, d.key, this);
        return availableHeight - self.yScale(d.y);
    })
    .attr('y', function(d){ return self.yScale(d.y); })
    .attr('x', function(d, i){ return i * 5 });
  • 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-08T01:37:11+00:00Added an answer on June 8, 2026 at 1:37 am

    You can achieve this by adjusting either the transform of the g.container or the x attribute of the appended rectangles. I would adjust the transforms, i.e. change

    .attr('transform', function(d, i){
      console.log(d.dimension, this)
      return 'translate('+ 
              (self.margin.left + self.xScale(d.dimension.value)) + ',' 
              + self.margin.top +')'
    });
    

    to include some extra space (half the difference between the dimension.values).

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

Sidebar

Related Questions

I have a column chart that I made using Adobe Flash Builder. I'd like
I'm creating a stacked bar chart just like this one . Notice that the
So I have this chart that's a little special. Kind of like an XY
I have a C-array that looks like this: char hexc[] = { 0x41, 0x80,
I have an array that is like this: unsigned char array[] = {'\xc0', '\x3f',
I have this function that converts all special chars to uppercase: function uc_latin1($str) {
I have a class User that looks like this: class User { private: char*
This chart has been linked a number of times on blogs that I follow
I bumped into this problem when I created a chart that need a axis
I have made a nibble class that appears to work, but when I use

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.