Accepted answer
  1. The timeParse assigned to the variable parseTimeUtc is the correct one considering the format of the dates in your data.
  2. Once you parse the dates in the forEach loop, you don't need to parse them again while setting the xAxis or within the line generator function.

    temp_data.forEach(function (d) { = parseTime_utc(
      d.temperature = +d.temperature;
  3. All the dates are the same and so I've made slight changes (months) to make the line visible.

  4. Added the following style to the line: fill:none; stroke: steelblue; to make the line visible.

  5. You had a SVG appended within a SVG (copy/paste error I suppose). Anyway, changed #watertemp_graph to a <div></div>.


var temp_data = [
{"temperature": "11.0", "date": "2018-08-22T14:53:37.267Z" },
 {"temperature": "11.2", "date": "2018-07-22T14:53:37.267Z" },
 {"temperature": "10.9", "date": "2018-08-22T14:53:37.267Z" },
 {"temperature": "11.3", "date": "2018-05-22T14:53:37.267Z" },
 {"temperature": "11.0", "date": "2018-08-22T14:53:37.267Z" }]

var parseDate = d3.timeParse("%Y-%m-%d %X"); //27-May-12 16:00:00. This is used for D3JS parsing
var formatTime = d3.timeFormat("%Y-%m-%d %X");
 var parseTime_utc = d3.timeParse("%Y-%m-%dT%H:%M:%S.%LZ");
var formatDate_utc = d3.timeFormat("%b %d, %Y %H:%M:%S");
// var parse = parseDate(moment.utc("YYYY-MM-DD HH:mm:ss"))

temp_data.forEach(function (d) { = parseTime_utc(
        d.temperature = +d.temperature;

var margin = { top: 30, right: 10, bottom: 50, left: 70 },
      width = 600 - margin.left - margin.right,
      height = 300 - - margin.bottom;

    // Parse the date / time

    // Set the ranges
    var x = d3.scaleTime().range([0, width]);
    var y = d3.scaleLinear().range([height, 0]);

    // Define the axes
    var xAxis = d3.axisBottom(x)

    var yAxis = d3.axisLeft(y)

    // Define the line
    var valueline = d3.line()
      .x(function (d) { return x(d['date']); })
      .y(function (d) { return y(d['temperature']); });

    // Adds the svg canvas
    var svg ="#" + "watertemp_graph")
      .attr("width", width + margin.left + margin.right)
      .attr("height", height + + margin.bottom)
        "translate(" + margin.left + "," + + ")");

    // Scale the range of the data
    x.domain(d3.extent(temp_data, function (d) { return; }));
    y.domain(d3.extent(temp_data, function (d) { return d['temperature']; }));

    // Add the valueline path.
      .attr("class", "line")
      .attr("d", valueline(temp_data)).style('fill', 'none').style('stroke', 'steelblue');

    // Add the X Axis
      .attr("class", "x axis")
      .attr("transform", "translate(0," + height + ")")

    // Add the Y Axis
      .attr("class", "y axis")
<script src=""></script>
<div id="watertemp_graph">

Updated codepen:

Also, if you could let us know why you have the other timeParsers and timeFormats, maybe I can help you with using those as well.

Hope this helps.

UPDATE: Need of a flexible parser?

As stated in the docs by Mike: If a more flexible parser is desired, try multiple formats sequentially until one returns non-null and my suggestion would be to be to further validate the non-null value (date) by following this answer here.

Related Query

More Query from same tag