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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:31:21+00:00 2026-06-11T21:31:21+00:00

I have some pretty simple code to plot a time series line graph. The

  • 0

I have some pretty simple code to plot a time series line graph. The x-scale is rendered correctly, however the line is not being rendered.

I am pretty sure that the issue we are facing here is with my function for calculating the x axis value, but I can’t see what I might be doing wrong

My code for the graph is similar to this:

var data = getData();
var graph;
var line;

function getData() {
    var theDate = new Date(2012, 01, 01, 0, 0, 0, 0);
    var arr = [];
    for (var x = 0; x < 30; x++) {
        arr.push([theDate.getTime(), rand(100)]);
        theDate.setDate(theDate.getDate() + 1);
    }
    return arr;
}

function rand(max) {
    return Math.floor(Math.random() * (max + 1))
}

var m = [80, 80, 80, 80]; // margins
var w = 1000 - m[1] - m[3]; // width
var h = 400 - m[0] - m[2]; // height

// pretty sure the issue is which this line
var x = d3.time.scale().domain([new Date(data[0][0]), new Date(data[data.length - 1][0])]).range([0, w]);
var y = d3.scale.linear().domain([0, 100]).range([h, 0]);

line = d3.svg.line()
             .x(function (d, i) { return x(new Date(d[0])); })    
             .y(function (d) { return y(d[1]); }) 
             .interpolate("linear")

graph = d3.select("#graph").append("svg:svg")
              .attr("width", w + m[1] + m[3])
              .attr("height", h + m[0] + m[2])
              .append("svg:g")
              .attr("transform", "translate(" + m[3] + "," + m[0] + ")");

var xAxis = d3.svg.axis().scale(x).ticks(d3.time.days, 1).tickFormat(d3.time.format("%d"));

graph.append("svg:g")
          .attr("class", "x axis")
          .attr("transform", "translate(0," + h + ")")
          .call(xAxis);

var yAxisLeft = d3.svg.axis().scale(y).ticks(10).orient("left");

graph.append("svg:g")
          .attr("class", "y axis")
          .attr("transform", "translate(0,0)") //positon of the y axis
          .call(yAxisLeft);

graph.append("svg:path")
         .data([data])
         .attr("class", "line")
         .attr("transform", "translate(" + x(1) + ")")
         .attr("d", line)
         .transition()
         .duration(1500)
         .ease("linear")
         .attr("transform", "translate(" + x(0) + ")");
  • 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-11T21:31:23+00:00Added an answer on June 11, 2026 at 9:31 pm

    I figured it out, changing

    graph.append("svg:path")
         .data([data])
         .attr("class", "line")
         .attr("transform", "translate(" + x(1) + ")")
         .attr("d", line)
         .transition()
         .duration(1500)
         .ease("linear")
         .attr("transform", "translate(" + x(0) + ")");
    

    to

    graph.append("svg:path")
         .data([data])
         .attr("class", "line")
    

    worked.

    Obviously my transition for the x axis is incorrect

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

Sidebar

Related Questions

I have a pretty simple line graph that is rendered by the code below.
I have some pretty simple Java code in which I'm starting another process and
I have some pretty simple code: var overlay = { show: function() { var
I have some pretty simple code: from mongoengine import * class Comment(Document): id =
I have some pretty simple code that reads lines from a network stream that
These are probably are pretty simple YES|NO type questions. I have some NSDictionaries containing
I have a pretty simple UIScrollView defined inside Interface Builder. I've pasted in some
Pretty simple question. I have a few ASP RequiredFieldValdators checking some text boxes. Out
this is just some pretty standard code I have tried. What I am trying
I have a pretty simple question, but for some reason I am drawing a

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.