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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:29:36+00:00 2026-06-17T01:29:36+00:00

I’m playing around with D3 and want tick lines to cut through a linear

  • 0

I’m playing around with D3 and want tick lines to cut through a linear time graph across the vertical axis. The tick line elements are there, with the correct vectors, but they do not appear. What appears instead is the path element that runs horizontally with the tick labels.

JSFiddle Link

var width = 960;
var height = 200;
var container = d3.select(".timeTable");
var svg = container.append("svg")
    .attr("width", width)
    .attr("height", height);
var roomID = container.attr("data-room");
var times = [
    {"from":"2012-12-27 00:00:00","until":"2012-12-27 12:00:00"},
    {"from":"2012-12-27 00:00:00","until":"2012-12-27 23:59:00"},
    {"from":"2012-12-27 02:00:00","until":"2012-12-27 04:00:00"},
    {"from":"2012-12-27 03:00:00","until":"2012-12-27 21:00:00"},
    {"from":"2012-12-27 03:30:00","until":"2012-12-27 04:50:00"},
    {"from":"2012-12-27 05:00:00","until":"2012-12-27 12:00:00"},
    {"from":"2012-12-27 09:00:00","until":"2012-12-27 15:00:00"},
    {"from":"2012-12-27 13:00:00","until":"2012-12-27 23:00:00"},
    {"from":"2012-12-27 13:00:00","until":"2012-12-27 23:30:00"},
    {"from":"2012-12-27 20:00:00","until":"2012-12-27 23:59:00"},
    {"from":"2012-12-27 20:00:00","until":"2012-12-27 22:00:00"},
    {"from":"2012-12-27 23:00:00","until":"2012-12-27 23:30:00"},
    {"from":"2012-12-28 01:00:00","until":"2012-12-28 13:00:00"}
];
function draw(times) {
    // domain
    var floor = d3.time.day.floor(d3.min(times, function (d) { return new Date(d.from); }));
    var ceil = d3.time.day.ceil(d3.max(times, function (d) { return new Date(d.until); }));
    // define linear time scale
    var x = d3.time.scale()
        .domain([floor, ceil])
        .rangeRound([0, width]);
    // define x axis
    var xAxis = d3.svg.axis()
        .scale(x)
        .orient('bottom')
        .ticks(d3.time.hours, 6)
        .tickSize(4);
    // draw time bars
    svg.selectAll("rect")
        .data(times)
        .enter().append("rect")
            .attr("class", "timeRange")
            .attr("width", function (d, i) { return x(new Date(d.until)) - x(new Date(d.from)); })
            .attr("height", "10px")
            .attr("x", function (d, i) { return x(new Date(d.from)); })
            .attr("y", function (d, i) { return i * 11; });
    // draw x axis
    svg.append("g")
        .attr("class", "xAxis")
        .attr("transform", "translate(0, " + (height - 23) + ")")
        .call(xAxis);
}
draw(times);

The path element generated simply overlaps the ticks, but the ticks are not visible even with path removed.

The desired tick effect is shown here Population Pyramid – ticks on the vertical axis have a line that cuts through the rest of the graph.

Is there different behavior I need to be aware of for time scales?

Much appreciated.

Chrome 23, D3 v3

  • 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-17T01:29:37+00:00Added an answer on June 17, 2026 at 1:29 am

    The trick to getting the tick lines into the plot area is to actually make a second axis and hide the labels. So your code plus the grid lines looks something like (fiddle):

    // draw x axis
    var xAxisLine = svg.append("g")
        .attr("class", "xAxis")
        .attr("transform", "translate(0, " + (height - 23) + ")")
        .call(xAxis);
    
    xAxisLine.selectAll("path.domain").attr("stroke","black").style('fill','none');
    xAxisLine.selectAll("line.tick").style('stroke','black');
    
    xAxis.tickSize(height-23);
    var xAxisLineOver = svg.append("g")
        .attr("class", "xAxis-overlay")
        .attr("transform", "translate(0,0)")
        .call(xAxis);
    
    xAxisLineOver.selectAll("path.domain").attr("stroke-width",0).style('fill','none');
    xAxisLineOver.selectAll("line.tick").style('stroke','red');
    xAxisLineOver.selectAll("text").text("");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm interested in microtypography issues on the web. I want a tool to fix:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I want to construct a data frame in an Rcpp function, but when I
i want to parse a xhtml file and display in UITableView. what is the

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.