ajax - How would d3.js difference chart example work with json data? -
i have been struggling example:
http://bl.ocks.org/mbostock/3894205
...to work json can use in portlet live data. can see data elements if alert component isn't rendering. y axis , label show up.
the part may wrong is:
d3.json("data.json", function(error, data) { if(error) return console.warn(error); data.data.foreach(function(d) { d.date = parsedate(d.date); d["san francisco"]= +d["san francisco"]; d["new york"] = +d["new york"]; count++; if (count>360) { alert(d.date + " " + d["san francisco"] + " " + d["new york"]); } });
taken html file
<!doctype html> <meta charset="utf-8"> <style> body { font: 10px sans-serif; } .axis path, .axis line { fill: none; stroke: #000; shape-rendering: crispedges; } .x.axis path { display: none; } .area.above { fill: rgb(252,141,89); } .area.below { fill: rgb(145,207,96); } .line { fill: none; stroke: #000; stroke-width: 1.5px; } </style> <body> <script src="http://d3js.org/d3.v3.min.js"></script> <script> var margin = {top: 20, right: 20, bottom: 30, left: 50}, width = 960 - margin.left - margin.right, height = 500 - margin.top - margin.bottom; var parsedate = d3.time.format("%y%m%d").parse; var x = d3.time.scale() .range([0, width]); var y = d3.scale.linear() .range([height, 0]); var xaxis = d3.svg.axis() .scale(x) .orient("bottom"); var yaxis = d3.svg.axis() .scale(y) .orient("left"); var line = d3.svg.area() .interpolate("basis") .x(function(d) { return x(d.date); }) .y(function(d) { return y(d["new york"]); }); var area = d3.svg.area() .interpolate("basis") .x(function(d) { return x(d.date); }) .y1(function(d) { return y(d["new york"]); }); var svg = d3.select("body").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); var count =0; d3.json("data.json", function(error, data) { if(error) return console.warn(error); data.data.foreach(function(d) { d.date = parsedate(d.date); d["san francisco"]= +d["san francisco"]; d["new york"] = +d["new york"]; count++; if (count>360) { alert(d.date + " " + d["san francisco"] + " " + d["new york"]); } }); x.domain(d3.extent(data, function(d) { return d.date; })); y.domain([ d3.min(data, function(d) { return math.min(d["new york"], d["san francisco"]); }), d3.max(data, function(d) { return math.max(d["new york"], d["san francisco"]); }) ]); svg.datum(data); svg.append("clippath") .attr("id", "clip-below") .append("path") .attr("d", area.y0(height)); svg.append("clippath") .attr("id", "clip-above") .append("path") .attr("d", area.y0(0)); svg.append("path") .attr("class", "area above") .attr("clip-path", "url(#clip-above)") .attr("d", area.y0(function(d) { return y(d["san francisco"]); })); svg.append("path") .attr("class", "area below") .attr("clip-path", "url(#clip-below)") .attr("d", area); svg.append("path") .attr("class", "line") .attr("d", line); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + height + ")") .call(xaxis); svg.append("g") .attr("class", "y axis") .call(yaxis) .append("text") .attr("transform", "rotate(-90)") .attr("y", 6) .attr("dy", ".71em") .style("text-anchor", "end") .text("temperature (ºf)"); }); </script>
using following data.json file
{"data":[ {"date":"20111001","new york":83.4,"san francisco":82.7}, {"date":"20111002","new york":78.1,"san francisco":79.9}, {"date":"20111003","new york":73.3,"san francisco":79.1}, {"date":"20111004","new york":75.7,"san francisco":78.8}, {"date":"20111005","new york":84.2,"san francisco":78.7}, {"date":"20111006","new york":78.8,"san francisco":77}, {"date":"20111007","new york":77.9,"san francisco":76.7}, {"date":"20111008","new york":81.8,"san francisco":76.8}, {"date":"20111009","new york":89.3,"san francisco":76.7}, {"date":"20111010","new york":91.2,"san francisco":80.1}, {"date":"20111011","new york":88.7,"san francisco":81.1}, {"date":"20111012","new york":81.8,"san francisco":81.5}, {"date":"20111013","new york":83.1,"san francisco":84.3}, {"date":"20111014","new york":86.9,"san francisco":87.1}, {"date":"20111015","new york":81.7,"san francisco":84.6}, {"date":"20111016","new york":81.8,"san francisco":81.6}, {"date":"20111017","new york":82.8,"san francisco":81.1}, {"date":"20111018","new york":80.8,"san francisco":79.2}, {"date":"20111019","new york":82.1,"san francisco":78.9}, {"date":"20111020","new york":85.1,"san francisco":77.2}, {"date":"20111021","new york":75.6,"san francisco":76.4}, {"date":"20111022","new york":74.4,"san francisco":80.7}, {"date":"20111023","new york":74.4,"san francisco":85.1}, {"date":"20111024","new york":74.8,"san francisco":80.9}, {"date":"20111025","new york":77.9,"san francisco":76.1}, {"date":"20111026","new york":74.6,"san francisco":74.6}, {"date":"20111027","new york":74.4,"san francisco":76.1}, {"date":"20111028","new york":62.5,"san francisco":78.1}, {"date":"20111029","new york":60.9,"san francisco":77.5}, {"date":"20111030","new york":58.6,"san francisco":77.7}, {"date":"20111031","new york":64.2,"san francisco":75.1}, {"date":"20111101","new york":69.6,"san francisco":77.9}, {"date":"20111102","new york":67.2,"san francisco":84.6}, {"date":"20111103","new york":70.1,"san francisco":76.2}, {"date":"20111104","new york":70.1,"san francisco":70.5}, {"date":"20111105","new york":63.5,"san francisco":71.3}, {"date":"20111106","new york":63.8,"san francisco":72.6}, {"date":"20111107","new york":68.9,"san francisco":71.4}, {"date":"20111108","new york":75.5,"san francisco":70.6}, {"date":"20111109","new york":73.7,"san francisco":74.6}, {"date":"20111110","new york":77.7,"san francisco":75.6}, {"date":"20111111","new york":68.5,"san francisco":73.9}, {"date":"20111112","new york":66.8,"san francisco":74}, {"date":"20111113","new york":71.1,"san francisco":73.8}, {"date":"20111114","new york":76.8,"san francisco":73.5}, {"date":"20111115","new york":79.7,"san francisco":73.4}, {"date":"20111116","new york":76.5,"san francisco":72.2}, {"date":"20111117","new york":69.6,"san francisco":72.7}, {"date":"20111118","new york":61.5,"san francisco":73.1}, {"date":"20111119","new york":64.3,"san francisco":69}, {"date":"20111120","new york":74.1,"san francisco":70.4}, {"date":"20111121","new york":74.1,"san francisco":71.1}, {"date":"20111122","new york":69.4,"san francisco":72.3}, {"date":"20111123","new york":70.1,"san francisco":74.6}, {"date":"20111124","new york":64.1,"san francisco":75.1}, {"date":"20111125","new york":70.3,"san francisco":71.5}, {"date":"20111126","new york":72.1,"san francisco":73.6}, {"date":"20111127","new york":69.6,"san francisco":72.3}, {"date":"20111128","new york":77.2,"san francisco":71}, {"date":"20111129","new york":79.1,"san francisco":69.5}, {"date":"20111130","new york":70.6,"san francisco":69.8}, {"date":"20111201","new york":64.3,"san francisco":80.4}, {"date":"20111202","new york":63.9,"san francisco":82.2}, {"date":"20111203","new york":62.1,"san francisco":78.3}, {"date":"20111204","new york":63.9,"san francisco":72.7}, {"date":"20111205","new york":70.2,"san francisco":71.5}, {"date":"20111206","new york":74.2,"san francisco":69.9}, {"date":"20111207","new york":74.6,"san francisco":68.6}, {"date":"20111208","new york":63.4,"san francisco":66.4}, {"date":"20111209","new york":62.2,"san francisco":69.8}, {"date":"20111210","new york":65.1,"san francisco":72.1}, {"date":"20111211","new york":53.8,"san francisco":68.8}, {"date":"20111212","new york":56.8,"san francisco":67.4}, {"date":"20111213","new york":58.6,"san francisco":67.2}, {"date":"20111214","new york":61.9,"san francisco":66.1}, {"date":"20111215","new york":69.6,"san francisco":68.8}, {"date":"20111216","new york":70.2,"san francisco":67.9}, {"date":"20111217","new york":60.6,"san francisco":69.8}, {"date":"20111218","new york":49.1,"san francisco":69.1}, {"date":"20111219","new york":53.7,"san francisco":68.3}, {"date":"20111220","new york":65.8,"san francisco":69.3}, {"date":"20111221","new york":67.4,"san francisco":68.4}, {"date":"20111222","new york":74.4,"san francisco":73.3}, {"date":"20111223","new york":67.8,"san francisco":67.5}, {"date":"20111224","new york":54.9,"san francisco":67.9}, {"date":"20111225","new york":55.9,"san francisco":68.9}, {"date":"20111226","new york":63.6,"san francisco":65.9}, {"date":"20111227","new york":62.9,"san francisco":67.2}, {"date":"20111228","new york":66.2,"san francisco":68.9}, {"date":"20111229","new york":50.8,"san francisco":70.9}, {"date":"20111230","new york":60.8,"san francisco":72.9}, {"date":"20111231","new york":69.8,"san francisco":70.1}, {"date":"20120101","new york":66.3,"san francisco":73.9}, {"date":"20120102","new york":63.2,"san francisco":73.1}, {"date":"20120103","new york":50.3,"san francisco":69.7}, {"date":"20120104","new york":39.2,"san francisco":72.7}, {"date":"20120105","new york":52.1,"san francisco":72.6}, {"date":"20120106","new york":61.2,"san francisco":69}, {"date":"20120107","new york":67.1,"san francisco":71}, {"date":"20120108","new york":66.1,"san francisco":76.8}, {"date":"20120109","new york":54.7,"san francisco":72.3}, {"date":"20120110","new york":59.4,"san francisco":71.6}, {"date":"20120111","new york":60.4,"san francisco":69.8}, {"date":"20120112","new york":65.4,"san francisco":71.9}, {"date":"20120113","new york":60.7,"san francisco":73.7}, {"date":"20120114","new york":50.4,"san francisco":72.9}, {"date":"20120115","new york":43.9,"san francisco":69.7}, {"date":"20120116","new york":42.6,"san francisco":65.3}, {"date":"20120117","new york":59.8,"san francisco":63.6}, {"date":"20120118","new york":63.2,"san francisco":65}, {"date":"20120119","new york":46.3,"san francisco":67.3}, {"date":"20120120","new york":52.8,"san francisco":71.4}, {"date":"20120121","new york":47.4,"san francisco":73.7}, {"date":"20120122","new york":45.1,"san francisco":68.3}, {"date":"20120123","new york":59.4,"san francisco":72.9}, {"date":"20120124","new york":68.7,"san francisco":69.1}, {"date":"20120125","new york":63.1,"san francisco":72.1}, {"date":"20120126","new york":57.1,"san francisco":73.6}, {"date":"20120127","new york":68.2,"san francisco":70.4}, {"date":"20120128","new york":63.7,"san francisco":70.3}, {"date":"20120129","new york":60.1,"san francisco":73.8}, {"date":"20120130","new york":58.0,"san francisco":71.9}, {"date":"20120131","new york":63.5,"san francisco":70}, {"date":"20120201","new york":70.4,"san francisco":70}, {"date":"20120202","new york":65.8,"san francisco":71.3}, {"date":"20120203","new york":57.5,"san francisco":71.5}, {"date":"20120204","new york":60.8,"san francisco":72}, {"date":"20120205","new york":56.5,"san francisco":73.8}, {"date":"20120206","new york":59.1,"san francisco":74.6}, {"date":"20120207","new york":63.2,"san francisco":74.3}, {"date":"20120208","new york":56.5,"san francisco":71.9}, {"date":"20120209","new york":56.5,"san francisco":73.8}, {"date":"20120210","new york":58.3,"san francisco":73.9}, {"date":"20120211","new york":56.9,"san francisco":72.3}, {"date":"20120212","new york":49.7,"san francisco":70.1}, {"date":"20120213","new york":53.1,"san francisco":69.5}, {"date":"20120214","new york":59.6,"san francisco":68.6}, {"date":"20120215","new york":62.3,"san francisco":69.9}, {"date":"20120216","new york":59.7,"san francisco":72.4}, {"date":"20120217","new york":66.0,"san francisco":69.9}, {"date":"20120218","new york":61.2,"san francisco":71.6}, {"date":"20120219","new york":59.8,"san francisco":67.8}, {"date":"20120220","new york":58.1,"san francisco":68.7}, {"date":"20120221","new york":57.1,"san francisco":69.7}, {"date":"20120222","new york":65.5,"san francisco":73.4}, {"date":"20120223","new york":70.6,"san francisco":74.1}, {"date":"20120224","new york":62.7,"san francisco":75.9}, {"date":"20120225","new york":62.6,"san francisco":71.7}, {"date":"20120226","new york":56.9,"san francisco":67.7}, {"date":"20120227","new york":60.9,"san francisco":65.4}, {"date":"20120228","new york":65.9,"san francisco":67}, {"date":"20120229","new york":60.7,"san francisco":69.8}, {"date":"20120301","new york":61.3,"san francisco":68.9}, {"date":"20120302","new york":56.8,"san francisco":68.1}, {"date":"20120303","new york":67.6,"san francisco":70.7}, {"date":"20120304","new york":64.2,"san francisco":75}, {"date":"20120305","new york":58.5,"san francisco":68.8}, {"date":"20120306","new york":52.9,"san francisco":68.4}, {"date":"20120307","new york":63.3,"san francisco":69.9}, {"date":"20120308","new york":71.2,"san francisco":69.2}, {"date":"20120309","new york":67.8,"san francisco":71.7}, {"date":"20120310","new york":57.2,"san francisco":69.3}, {"date":"20120311","new york":62.9,"san francisco":70}, {"date":"20120312","new york":68.8,"san francisco":68.6}, {"date":"20120313","new york":72.6,"san francisco":73.9}, {"date":"20120314","new york":80.5,"san francisco":75.2}, {"date":"20120315","new york":67.2,"san francisco":75.9}, {"date":"20120316","new york":64.7,"san francisco":74.6}, {"date":"20120317","new york":68.2,"san francisco":68.2}, {"date":"20120318","new york":68.2,"san francisco":67.1}, {"date":"20120319","new york":73.1,"san francisco":65.8}, {"date":"20120320","new york":77.8,"san francisco":69.7}, {"date":"20120321","new york":77.5,"san francisco":71.4}, {"date":"20120322","new york":77.3,"san francisco":71.4}, {"date":"20120323","new york":81.7,"san francisco":68.4}, {"date":"20120324","new york":75.8,"san francisco":69}, {"date":"20120325","new york":68.4,"san francisco":66.4}, {"date":"20120326","new york":69.8,"san francisco":69.7}, {"date":"20120327","new york":59.6,"san francisco":74.1}, {"date":"20120328","new york":69.7,"san francisco":74.6}, {"date":"20120329","new york":76.8,"san francisco":72.3}, {"date":"20120330","new york":66.5,"san francisco":74.5}, {"date":"20120331","new york":62.2,"san francisco":76.2}, {"date":"20120401","new york":65.3,"san francisco":71.1}, {"date":"20120402","new york":68.1,"san francisco":70.5}, {"date":"20120403","new york":71.2,"san francisco":72.2}, {"date":"20120404","new york":81.0,"san francisco":70.6}, {"date":"20120405","new york":70.7,"san francisco":67.9}, {"date":"20120406","new york":68.0,"san francisco":67.4}, {"date":"20120407","new york":71.1,"san francisco":69.4}, {"date":"20120408","new york":75.7,"san francisco":70}, {"date":"20120409","new york":78.3,"san francisco":71.3}, {"date":"20120410","new york":75.0,"san francisco":73.8}, {"date":"20120411","new york":69.0,"san francisco":72.9}, {"date":"20120412","new york":71.7,"san francisco":73.9}, {"date":"20120413","new york":73.1,"san francisco":70.2}, {"date":"20120414","new york":75.2,"san francisco":70.9}, {"date":"20120415","new york":82.3,"san francisco":71.5}, {"date":"20120416","new york":82.9,"san francisco":71.9}, {"date":"20120417","new york":89.3,"san francisco":73.2}, {"date":"20120418","new york":79.0,"san francisco":73}, {"date":"20120419","new york":74.1,"san francisco":75.1}, {"date":"20120420","new york":76.5,"san francisco":75.8}, {"date":"20120421","new york":78.2,"san francisco":78}, {"date":"20120422","new york":72.4,"san francisco":72.8}, {"date":"20120423","new york":71.6,"san francisco":75.1}, {"date":"20120424","new york":69.3,"san francisco":77.9}, {"date":"20120425","new york":72.5,"san francisco":77.5}, {"date":"20120426","new york":70.5,"san francisco":75.3}, {"date":"20120427","new york":71.9,"san francisco":73.5}, {"date":"20120428","new york":67.4,"san francisco":74.7}, {"date":"20120429","new york":74.1,"san francisco":74}, {"date":"20120430","new york":71.9,"san francisco":73.4}, {"date":"20120501","new york":77.4,"san francisco":72.7}, {"date":"20120502","new york":73.7,"san francisco":70.7}, {"date":"20120503","new york":73.1,"san francisco":72.6}, {"date":"20120504","new york":77.2,"san francisco":73.4}, {"date":"20120505","new york":77.0,"san francisco":73.1}, {"date":"20120506","new york":76.6,"san francisco":76.5}, {"date":"20120507","new york":74.6,"san francisco":75.3}, {"date":"20120508","new york":77.9,"san francisco":72}, {"date":"20120509","new york":79.2,"san francisco":72.4}, {"date":"20120510","new york":81.1,"san francisco":73.4}, {"date":"20120511","new york":79.7,"san francisco":73.1}, {"date":"20120512","new york":84.1,"san francisco":69.9}, {"date":"20120513","new york":85.3,"san francisco":72}, {"date":"20120514","new york":84.2,"san francisco":76}, {"date":"20120515","new york":82.0,"san francisco":73}, {"date":"20120516","new york":83.8,"san francisco":71}, {"date":"20120517","new york":84.5,"san francisco":71.4}, {"date":"20120518","new york":81.0,"san francisco":72.2}, {"date":"20120519","new york":82.6,"san francisco":72.4}, {"date":"20120520","new york":86.2,"san francisco":74.5}, {"date":"20120521","new york":82.7,"san francisco":72.8}, {"date":"20120522","new york":83.7,"san francisco":73.9}, {"date":"20120523","new york":86.4,"san francisco":76.5}, {"date":"20120524","new york":84.5,"san francisco":74.7}, {"date":"20120525","new york":85.4,"san francisco":72.5}, {"date":"20120526","new york":89.4,"san francisco":72.1}, {"date":"20120527","new york":91.9,"san francisco":72.2}, {"date":"20120528","new york":94.4,"san francisco":72.9}, {"date":"20120529","new york":95.9,"san francisco":72.1}, {"date":"20120530","new york":92.9,"san francisco":72.1}, {"date":"20120531","new york":92.5,"san francisco":73.3}, {"date":"20120601","new york":87.2,"san francisco":74.8}, {"date":"20120602","new york":88.3,"san francisco":74}, {"date":"20120603","new york":87.7,"san francisco":72.3}, {"date":"20120604","new york":81.9,"san francisco":75.3}, {"date":"20120605","new york":78.3,"san francisco":73.5}, {"date":"20120606","new york":81.7,"san francisco":74.1}, {"date":"20120607","new york":86.7,"san francisco":73.9}, {"date":"20120608","new york":88.7,"san francisco":74.4}, {"date":"20120609","new york":92.2,"san francisco":75}, {"date":"20120610","new york":92.6,"san francisco":80}, {"date":"20120611","new york":89.2,"san francisco":77.2}, {"date":"20120612","new york":86.9,"san francisco":75.1}, {"date":"20120613","new york":86.7,"san francisco":73.3}, {"date":"20120614","new york":87.7,"san francisco":73.4}, {"date":"20120615","new york":88.5,"san francisco":74.6}, {"date":"20120616","new york":87.5,"san francisco":77}, {"date":"20120617","new york":84.2,"san francisco":75.6}, {"date":"20120618","new york":81.7,"san francisco":72.5}, {"date":"20120619","new york":86.4,"san francisco":73.9}, {"date":"20120620","new york":97.9,"san francisco":75.3}, {"date":"20120621","new york":108.0,"san francisco":73.3}, {"date":"20120622","new york":102.0,"san francisco":74.1}, {"date":"20120623","new york":97.0,"san francisco":75.2}, {"date":"20120624","new york":95.4,"san francisco":75.8}, {"date":"20120625","new york":90.9,"san francisco":76.8}, {"date":"20120626","new york":85.9,"san francisco":77.5}, {"date":"20120627","new york":93.5,"san francisco":77.7}, {"date":"20120628","new york":97.4,"san francisco":76.6}, {"date":"20120629","new york":99.6,"san francisco":76.4}, {"date":"20120630","new york":104.0,"san francisco":78.4}, {"date":"20120701","new york":101.0,"san francisco":78.8}, {"date":"20120702","new york":102.0,"san francisco":76.4}, {"date":"20120703","new york":100.0,"san francisco":76.5}, {"date":"20120704","new york":97.8,"san francisco":75.8}, {"date":"20120705","new york":106.0,"san francisco":74.8}, {"date":"20120706","new york":99.9,"san francisco":74.9}, {"date":"20120707","new york":103.0,"san francisco":74.7}, {"date":"20120708","new york":101.0,"san francisco":72.8}, {"date":"20120709","new york":97.8,"san francisco":73.7}, {"date":"20120710","new york":96.1,"san francisco":73.1}, {"date":"20120711","new york":96.3,"san francisco":72.7}, {"date":"20120712","new york":95.8,"san francisco":72}, {"date":"20120713","new york":97.2,"san francisco":73.4}, {"date":"20120714","new york":99.3,"san francisco":74}, {"date":"20120715","new york":98.9,"san francisco":74}, {"date":"20120716","new york":99.6,"san francisco":74.5}, {"date":"20120717","new york":103.0,"san francisco":76.7}, {"date":"20120718","new york":104.0,"san francisco":77.5}, {"date":"20120719","new york":95.1,"san francisco":77.1}, {"date":"20120720","new york":88.4,"san francisco":78.1}, {"date":"20120721","new york":88.4,"san francisco":77.6}, {"date":"20120722","new york":92.2,"san francisco":76}, {"date":"20120723","new york":95.6,"san francisco":76.6}, {"date":"20120724","new york":102.0,"san francisco":77.8}, {"date":"20120725","new york":98.4,"san francisco":77.5}, {"date":"20120726","new york":97.0,"san francisco":76.4}, {"date":"20120727","new york":99.4,"san francisco":75.3}, {"date":"20120728","new york":97.4,"san francisco":75}, {"date":"20120729","new york":92.5,"san francisco":75.6}, {"date":"20120730","new york":92.9,"san francisco":75.6}, {"date":"20120731","new york":93.6,"san francisco":75.9}, {"date":"20120801","new york":95.0,"san francisco":75.4}, {"date":"20120802","new york":97.7,"san francisco":74.4}, {"date":"20120803","new york":99.7,"san francisco":73.7}, {"date":"20120804","new york":99.6,"san francisco":74.1}, {"date":"20120805","new york":101.0,"san francisco":77.8}, {"date":"20120806","new york":100.0,"san francisco":78.2}, {"date":"20120807","new york":95.7,"san francisco":78}, {"date":"20120808","new york":97.8,"san francisco":77}, {"date":"20120809","new york":98.6,"san francisco":75}, {"date":"20120810","new york":97.8,"san francisco":74.8}, {"date":"20120811","new york":98.5,"san francisco":73}, {"date":"20120812","new york":98.8,"san francisco":72.5}, {"date":"20120813","new york":98.6,"san francisco":73.3}, {"date":"20120814","new york":96.8,"san francisco":73.9}, {"date":"20120815","new york":96.7,"san francisco":76.2}, {"date":"20120816","new york":95.9,"san francisco":77.1}, {"date":"20120817","new york":97.6,"san francisco":75.3}, {"date":"20120818","new york":92.6,"san francisco":76.2}, {"date":"20120819","new york":90.4,"san francisco":74.3}, {"date":"20120820","new york":91.8,"san francisco":73.1}, {"date":"20120821","new york":93.6,"san francisco":73.4}, {"date":"20120822","new york":94.7,"san francisco":74.5}, {"date":"20120823","new york":94.6,"san francisco":75.7}, {"date":"20120824","new york":96.0,"san francisco":74.8}, {"date":"20120825","new york":96.2,"san francisco":73.8}, {"date":"20120826","new york":93.4,"san francisco":76.5}, {"date":"20120827","new york":94.6,"san francisco":78.3}, {"date":"20120828","new york":99.4,"san francisco":78.7}, {"date":"20120829","new york":94.7,"san francisco":77.5}, {"date":"20120830","new york":93.5,"san francisco":75.9}, {"date":"20120831","new york":97.9,"san francisco":75.4}, {"date":"20120901","new york":100.0,"san francisco":75.7}, {"date":"20120902","new york":95.1,"san francisco":73.1}, {"date":"20120903","new york":93.5,"san francisco":73.5}, {"date":"20120904","new york":93.5,"san francisco":72.5}, {"date":"20120905","new york":97.7,"san francisco":74.5}, {"date":"20120906","new york":94.2,"san francisco":76.3}, {"date":"20120907","new york":96.0,"san francisco":76.4}, {"date":"20120908","new york":97.1,"san francisco":76.5}, {"date":"20120909","new york":89.7,"san francisco":76.4}, {"date":"20120910","new york":87.8,"san francisco":75.4}, {"date":"20120911","new york":84.0,"san francisco":76.2}, {"date":"20120912","new york":88.1,"san francisco":75.7}, {"date":"20120913","new york":89.3,"san francisco":74.3}, {"date":"20120914","new york":90.0,"san francisco":75.2}, {"date":"20120915","new york":89.3,"san francisco":74.3}, {"date":"20120916","new york":86.3,"san francisco":72.9}, {"date":"20120917","new york":87.0,"san francisco":74.8}, {"date":"20120918","new york":92.8,"san francisco":74.8}, {"date":"20120919","new york":87.2,"san francisco":76.8}, {"date":"20120920","new york":82.1,"san francisco":75.4}, {"date":"20120921","new york":84.0,"san francisco":75.8}, {"date":"20120922","new york":85.5,"san francisco":75.9}, {"date":"20120923","new york":85.7,"san francisco":72.8}, {"date":"20120924","new york":80.4,"san francisco":74.5}, {"date":"20120925","new york":83.2,"san francisco":73.3}, {"date":"20120926","new york":88.5,"san francisco":73.6}, {"date":"20120927","new york":89.2,"san francisco":72.1}, {"date":"20120928","new york":88.7,"san francisco":72.6}, {"date":"20120929","new york":82.5,"san francisco":73.9}, {"date":"20120930","new york":82.3,"san francisco":75.1}]}
the problem data nested in data
element. need update code reflect that. specifically, lines
x.domain(d3.extent(data, function(d) { return d.date; })); y.domain([ d3.min(data, function(d) { return math.min(d["new york"], d["san francisco"]); }), d3.max(data, function(d) { return math.max(d["new york"], d["san francisco"]); }) ]); svg.datum(data);
need changed to
x.domain(d3.extent(data.data, function(d) { return d.date; })); y.domain([ d3.min(data.data, function(d) { return math.min(d["new york"], d["san francisco"]); }), d3.max(data.data, function(d) { return math.max(d["new york"], d["san francisco"]); }) ]); svg.datum(data.data);
Comments
Post a Comment