javascript - How to force the nvd3 chart timespan to stretch the width of the chart? -
http://plnkr.co/edit/ymrqiogtbqf6tvmtvc4t?p=preview
i have latest d3 , nvd3 libraries in plnkr above. when first view chart, notice timespan ticks 09:00, 08:30, 08:00 etc squished/overlaid on top of each other on left xaxis.
now timespans not correctly stretch length of chart until user either clicks on time range finder below chart, or resizes window.
currently chart looks on first load:
when should looks this:
any idea i'm going wrong? found question here nvd3 set expanded default answer did not work me.
my nv.addgraph code
var data =[{ "key" : "price", "color" : "#4c73ff", "values" : [ [ 1443621600000 , 71.89], [ 1443619800000 , 75.51], [ 1443618000000 , 68.49], [ 1443616200000 , 62.72], [ 1443612600000 , 70.39], [ 1443610800000 , 59.77]] }]; nv.addgraph(function() { var chart = nv.models.lineplusbarchart() .margin({top: 20, right: 40, bottom: 50, left: 40}) .x(function(d,i) { return }) .y(function(d) { return d[1] }) .color(d3.scale.category10().range()); chart.xaxis.tickformat(function(d) { var dx = data[0].values[d] && data[0].values[d][0] || 0; // return time in hours: return d3.time.format('%i:%m')(new date(dx)) }); chart.y1axis .tickformat(d3.format(',f')); chart.y2axis .tickformat(function(d) { return '$' + d3.format(',f')(d) }); chart.bars.forcey([0]); chart.lines.interactive(false); chart.height(300); chart.nodata("there no data display @ moment."); // remove legend: chart.showlegend(false); d3.select('#chart svg') .datum(data) .transition().duration(500) .call(chart); nv.utils.windowresize(chart.update); return chart; });
just figured out!
d3.select('#chart svg') .datum(res) .transition().duration(500) .call(chart); chart.update(); // <- needed add // nv.utils.windowresize(chart.update); the following line useless: nv.utils.windowresize(chart.update);
i moved chart.update out of , apparently needed trigger timespan stretch out.


Comments
Post a Comment