mcaule / d3-timeseries

Time series charting library based on d3.js
143 stars 39 forks source link

Expanded tooltip not displaying #2

Open lukewendling opened 7 years ago

lukewendling commented 7 years ago

I'm looking for assistance in understanding the tooltip display.

Problem: I only see the minimal date text in the tooltip, instead of the additional label and coloring.

image

This bit of code is why

serie.find = function (date) {
    var bisect = d3.bisector(fk(aes.x)).left;
    var i = bisect(serie.data, date) - 1
    if (i == -1)
        return null
    //look to far after serie is defined
    if (i == serie.data.length - 1 && serie.data.length > 1 &&
        Number(date) - Number(serie.data[i][aes.x]) > Number(serie.data[i][aes.x]) - Number(serie.data[i - 1][aes.x]))
        return null /******** this is always returned *************/
    return serie.data[i]
}

Data looks like this

[{query_type: "jobset", count: 100, created: 1488393368058}]

Chart config:

var chart = d3.timeseries()
        .addSerie(
        data,
        { x: 'created', y: ofX },
        { interpolate: 'linear', width: 3 }
        )
        .margin.left(65)
        .width(650)

Any ideas greatly appreciated!

crlsktr commented 5 years ago

Hi Luke! Sorry I'm so late to this. I ran into the same problem. I figured that the problem is in the subtraction of the dates. If your dates have hours (which usually happens on the constructor of Date because of localization) then there is the possibility that Number(date) - Number(serie.data[i][aes.x]) will indeed be greater than Number(serie.data[i][aes.x]) - Number(serie.data[i - 1][aes.x]). The solution is to remove hours.