I'm trying to use a JSON variable to populate a bar chart, but when I attempt to set the max value of the y domain the code pulls back the wrong value.
var sample_data = {"category":
{"categoryname":"Beverages","num_products":"12"},
{"categoryname":"Condiments","num_products":"12"},
{"categoryname":"Confections","num_products":"13"},
{"categoryname":"Dairy Products","num_products":"10"},
{"categoryname":"Grains/Cereals","num_products":"7"},
{"categoryname":"Meat/Poultry","num_products":"6"},
{"categoryname":"Produce","num_products":"5"},
{"categoryname":"Seafood","num_products":"12"}]};
The code always returns 7, and not 13.
function loadJSONChart(data) {
...
x.domain(data.category.map(function(d) { return d.categoryname; }));
y.domain([0, d3.max(data.category, function(d) { return d.num_products; })]);
...
What am I doing wrong?