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 8867829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:08:05+00:00 2026-06-14T17:08:05+00:00

Here is a link to a d3 js graph. http://enjalot.com/inlet/4131006/ And here is the

  • 0

Here is a link to a d3 js graph.

http://enjalot.com/inlet/4131006/

And here is the code

    var w = 300,
    h = 300,
    padding = 31,
    p = 10;

var data = [{count:200,year:2008},
    {count:240,year:2010},
    {count:290,year:2009}];

var bar_height = d3.scale.linear()
    .domain(d3.extent(data, function(d) { return d.count; }) )  // min max of count
    .range([p,h-p]);  // min max of area to plot in


var bar_xpos = d3.scale.linear()
    .domain(d3.extent(data, function(d) { return d.year; }) )  // min max of year
    .range([p,w-p]);  // min max of area to plot in


var xAxis = d3.svg.axis()
            .scale(bar_xpos)
            .orient("bottom")
            .ticks(5);  //Set rough # of ticks

var yAxis = d3.svg.axis()
            .scale(bar_height)
            .orient("left")
            .ticks(5);

var svg = d3.select("svg")
    .attr("width", w)
    .attr("height", h);

svg.append("g")
    .attr("class", "axis")
    .attr("transform", "translate(0," + (h - padding) + ")")
    .call(xAxis);

svg.append("g")
    .attr("class", "axis")
    .attr("transform", "translate(" + padding + ",0)")
    .call(yAxis);

svg.selectAll("rect")
    .data(data)
    .enter().append("rect")
    .attr("x", function(d) {
        return bar_xpos(d.year); })
    .attr("y", function(d) { 
        return h - bar_height(d.count); })
    .attr("width", 10)
    .attr("height", function(d) {return bar_height(d.count); })
    .attr("fill", "steelblue")

I have been able to draw y axis and x axis to this graph but they do not look correct.There are some issue
The rectangle line in not on the X axis.
There is no 0 on x axis and y axis on the graph.It starts with the min value from the json data.And is dere any way to configure the distance between two marks on the axis.

  • 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-14T17:08:06+00:00Added an answer on June 14, 2026 at 5:08 pm

    To configure your axes, you have to modify your scales.

    var bar_height = d3.scale.linear()
        .domain(d3.extent(data, function(d) { return d.count; }) )  // min max of count
        .range([p,h-p]);  // min max of area to plot in
    
    
    var bar_xpos = d3.scale.linear()
        .domain(d3.extent(data, function(d) { return d.year; }) )  // min max of year
        .range([p,w-p]);  // min max of area to plot in
    

    d3.extent() returns the min and max of your data simultaneously and use that as the domain of your graph. Because you use bar_height and bar_xpos to format your scales, the minimum values for the scales will also be the minimum values from the data. To fix this, use d3.max() instead, like so:

    var bar_height = d3.scale.linear()
        .domain([d3.max(data, function(d) { return d.count; }), 0] )  // min max of count
        .range([p,h-p]);  // min max of area to plot in
    
    
    var bar_xpos = d3.scale.linear()
        .domain([2000, d3.max(data, function(d) { return d.year; })] )  // min max of year
        .range([p,w-p]);  // min max of area to plot in
    

    You can use 0 for your bar_xpos min, but it doesn’t make sense if you are going by year because your data will be impossible to actually read. I used 2000 for the min here.

    Working example here.

    Also, in this example I formatted your bar location to line up a bit nicer with the axes. I replaced .attr('width', 10) with .attr('width', barwidth), and subtracted barwidth from the x attr as well. This will make the right edge of your bar line up with the right edge of the axis instead of spill over the edge.

    Edit:
    Modified the y and height attributes. The height was going the opposite way, under the graph otherwise. Link has been updated.

    .attr("y", function(d) { 
        return bar_height(d.count); })
    .attr("width", barwidth)
    .attr("height", function(d) {return h - bar_height(d.count) - padding; })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is link to my d3js graph http://enjalot.com/inlet/4159384/ Problem is that the y axis
I am trying to create a d3 force-directed graph ( http://mbostock.github.com/d3/ex/force.html ). Here is
Here is a link to the jsfiddle http://jsfiddle.net/jaimem/RPGPL/2/ Now the graph shows red color
Here is link where i got a code for web-page content fetching. But i
here is link to an example: http://techchorus.net/demos/jquery/hiding-input-elements-in-a-div.html It actally disables few elements on click
I'm learning by reading this tutorial: Link Here's the code: <?php require_once 'Zend/Loader.php'; class
Here is the link for my html http://jsfiddle.net/9rprY/18/ In this I need the middle
here is a link to what im basing my code off of....but i want
click here for jsfiddle highchart link: Column - Bar High Chart this code is
My idea is to implement something like this: https://i.stack.imgur.com/8BmW5.png screenshot is from here: http://www.thedrum.co.uk/opinion/2012/03/08/five-ways-new-facebook-timeline-will-impact-brands

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.