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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:28:39+00:00 2026-06-15T03:28:39+00:00

Here is link to my d3js graph http://enjalot.com/inlet/4159384/ Problem is that the y axis

  • 0

Here is link to my d3js graph http://enjalot.com/inlet/4159384/
Problem is that the y axis which shows Year is having values such as 2008.5 and 2009.0 for json data

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

I want to display Years without any decimal points.How to do it.
Here is my d3js code below

    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);
  • 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-15T03:28:41+00:00Added an answer on June 15, 2026 at 3:28 am

    Check out the docs on d3 value formatting.

    If you use d3.format() to format your axis, your axis values will look a lot nicer.

    var formatxAxis = d3.format('.0f');
    
    var xAxis = d3.svg.axis()
                .scale(bar_xpos)
                .orient("bottom")
                .tickFormat(formatxAxis)
                .ticks(5); 
    

    .0f means:
    I want a precision of 0 places after the decimal, and I want values to be fixed, i.e. not rounded but truncated.

    You’ll notice, however, that since you are fixing the precision to 0 places after the decimal, you will have 2009.5 and 2009.0 both being formatted to 2009. This will mean that two axis ticks could have the same value. This error will go away once you have enough data points over more years.

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

Sidebar

Related Questions

Here is a link to a d3 js graph. http://enjalot.com/inlet/4131006/ And here is the
Here is a link to the jsfiddle http://jsfiddle.net/jaimem/RPGPL/2/ Now the graph shows red color
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
Here is the link for my html http://jsfiddle.net/9rprY/18/ In this I need the middle
I have a weird problem. I have create a bar chart using d3js that
I have a jquery game that you can view here link text The game
I have a jquery game that you can view here link text The game
I came across this post here (link below) and it states that you can
This is a question that extends from the originally posted here: Link to loading-xaml
Could anyone help me with this problem? Code zip is here: (link taken down)

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.