BC date glitch for line charts, also: how to handle gaps?

35 views
Skip to first unread message

ewg4...@gmail.com

unread,
Apr 19, 2017, 2:03:40 PM4/19/17
to d3plus
I am attempting to render a line chart which may include B.C. dates. When d3plus attempts to render the chart when the JSON data contain B.C. dates (according to the XSD spec, where "-0010" is 10 B.C.--or does d3plus follow ISO8601?), the chart div simply says "No Data Available" in Firefox, but glitches out really badly in Chrome. See https://jsfiddle.net/ewg118/g7jp1sLb/

However, if I adjust my query to only include data from AD, the chart will render (https://jsfiddle.net/ewg118/n0ofuyky/1/).

However, these data show averages for small time spans over a longer time span. E.g., 5 year intervals from 50 B.C. to A.D. 50. The first node of data has a "value" of "-0050", but it really represents an average weight of a coin from 50 B.C. to 46 B.C. The next node is 45 B.C. to 41 B.C. So on and so forth. So when setting the .time('value') when drawing the chart, d3plus will insert ticks for the years in between 50 and 45 B.C., and instead of lines, I get a series of dots.

The alternative is that instead of valid XSD dates as the "value", the years are instead encoded as simple integers (-50 for 50 B.C.). But instead of displaying -50, -45, etc. along the x axis, I would instead like to display human-readable date ranges--the "label" in the JSON examples above. Is this possible? This negates the need to designate a .time() at all and therefore avoids the problem of having ticks for the years in between the start date of each smaller date range.

The last question I have is about how to handle gaps.

In the following example, I am using a simple integer as the value of the x axis: https://jsfiddle.net/ewg118/n0ofuyky/2/. The JSON data I work with are generated in real time from a SPARQL query. If my query is for the average weight of silver coins produced in Rome over a long period and there are no silver coins produced during a shorter period, the resulting average is '0', which is plotted on the y axis in d3plus. Is there a way to force d3plus not to draw a point for a 0 or null value without losing the x axis value? For example, if my script for generating the JSON skips any result where the average is 0, the x axis may skip from 20 to 40 AD, but it is equally important to demonstrate gaps in data to researchers, as this probably means that there were coins minted in Rome for a period. I tried the following:

.size({ "mute": function (node) {
return node.average > 0
}
})

But it didn't do what I thought it might.

Thanks for your help.

ewg4...@gmail.com

unread,
Apr 19, 2017, 2:13:40 PM4/19/17
to d3plus, ewg4...@gmail.com

Nevermind on the muting of null values on the y axis. This works:

.y({
'value': 'average',
mute: function (d) { return d == 0;}
})

Reply all
Reply to author
Forward
0 new messages