novus / nvd3

A reusable charting library written in d3.js
http://nvd3.org/
Other
7.22k stars 2.15k forks source link

wrong scaling when non numeric values are used #505

Open gdeb opened 10 years ago

gdeb commented 10 years ago

When this chart is given to nvd3:

var gdata = [{ key: "Revenue", values: [{x: "A", y: "15000"},{x: "B", y: "500"}, ]}]; nv.addGraph(function() { var chart = nv.models.multiBarChart(); d3.select('#chart svg').datum(gdata).call(chart); nv.utils.windowResize(chart.update); return chart; });

The library does not complain that string values are used instead of numeric values. But it will display a chart with correct numbers and wrong y-axis. The reason is that the computation of the y-axis range uses the <, > operator (so "500" > "15000") but the value is cast to a numeric value later on (as displayed on the tooltip).

It took me a while to understand what was going on, because most of my graphs were correct, but some of there had weird y range.

The solution could be to cast the values to number before computing the y range.

DavidSouther commented 10 years ago

I don't think the correct solution is cast/parsing to numbers. What we should do is when getting non-numeric values, is to collate the strings and use those as the tickValues for the underlying axis.