d3.js - Tool tip showing NaN error in D3 Multi Line Graph -


i have customized d3 multi series line graph according requirements. new d3 graphs , javascript. when added tooltip , ran code, showed me div 2 nan values. have been struggling quite long if 1 can me here, appreciated.

    <script>      var svg = d3.select("svg"),         margin = {top: 20, right: 80, bottom: 30, left: 140},         width = svg.attr("width") - margin.left - margin.right,         height = svg.attr("height") - margin.top - margin.bottom,         g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");      var parsetime = d3.timeparse("%y%m%d");       var x = d3.scaletime().range([0, width]),         y = d3.scalelinear().range([height, 0]),         z = d3.scaleordinal(d3.schemecategory10);      var line = d3.line()         .curve(d3.curvebasis)          .x(function(d) { return x(d.date); })         .y(function(d) { return y(d.temperature); });      var div = d3.select("body").append("div")            .attr("class", "tooltip")                        .style("opacity", 0);       d3.tsv("data.tsv", type, function(error, data) {       if (error) throw error;        var cities = data.columns.slice(1).map(function(id) {         return {           id: id,           values: data.map(function(d) {             return {date: d.date, temperature: d[id]};           })         };       });        x.domain(d3.extent(data, function(d) { return d.date; }));        y.domain([         d3.min(cities, function(c) { return d3.min(c.values, function(d) { return d.temperature; }); }),         d3.max(cities, function(c) { return d3.max(c.values, function(d) { return 0.02*d.temperature; }); })       ]);        z.domain(cities.map(function(c) { return c.id; }));        g.append("g")           .attr("class", "axis axis--x")           .attr("transform", "translate(0," + height + ")")           .call(d3.axisbottom(x));        g.append("g")           .attr("class", "axis axis--y")           .call(d3.axisleft(y))         .append("text")           .attr("transform", "rotate(-90)")           .attr("y", 6)           .attr("dy", "0.71em")           .attr("fill", "#000")           .text("time, ms");        var city = g.selectall(".city")         .data(cities)         .enter().append("g")           .attr("class", "city");        **city.append("path")           .attr("class", "line")           .attr("d", function(d) { return line(d.values); })           .style("stroke", function(d) { return z(d.id); })           .on("mouseover",  function(d) {                        div.transition()                             .duration(200)                           .style("opacity", .9);                       div .html(x(d.date)+"<br/>"  + y(d.temperature))                         .style("left", (d3.event.pagex) + "px")                          .style("top", (d3.event.pagey - 28) + "px");                     })                               .on("mouseout", function(d) {                        div.transition()                             .duration(500)                           .style("opacity", 0);                });**         city.append("text")           .datum(function(d) { return {id: d.id, value: d.values[d.values.length - 1]}; })           .attr("transform", function(d) { return "translate(" + x(d.value.date) + "," + y(d.value.temperature) + ")"; })           .attr("x",1)           .attr("dy", "0.38em")           .style("width","50px")           .style("font", "bold 10px sans-serif")           .text(function(d) { return d.id; });     });      function type(d, _, columns) {       d.date = parsetime(d.date);       (var = 1, n = columns.length, c; < n; ++i) d[c = columns[i]] = +d[c];       return d;     }      </script> 


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -