{"id":7533,"date":"2015-07-26T05:11:25","date_gmt":"2015-07-26T05:11:25","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/07\/26\/nvd3-line-chart-with-realtime-data-open-source-projects-novus-nvd3\/"},"modified":"2015-07-26T05:11:25","modified_gmt":"2015-07-26T05:11:25","slug":"nvd3-line-chart-with-realtime-data-open-source-projects-novus-nvd3","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/07\/26\/nvd3-line-chart-with-realtime-data-open-source-projects-novus-nvd3\/","title":{"rendered":"NVD3 line chart with realtime data-open source projects novus\/nvd3"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/e0ab25a1123a100fc400e27c694d9013?s=128&amp;d=identicon&amp;r=PG\" \/> <strong>kaliatech<\/strong><\/p>\n<p><strong>Second Answer<\/strong> (after comment)<\/p>\n<p>I looked at source for cumulativeLineChart. You can see the display.y property get created during chart creation. It relies on a private method: &#8220;indexify&#8221;. If some derivative of that method was made public, then perhaps you could do something like <code>chart.reindexify()<\/code> before redrawing.<\/p>\n<p>As a temporary workaround, you could recreate the chart from scratch on every update. If you remove the transition, that seems to work okay. Example jsfiddle: http:\/\/jsfiddle.net\/kaliatech\/PGyKF\/.<\/p>\n<p><strong>First Answer<\/strong><\/p>\n<p>I believe there is bug in cumulativeLineChart. It appears that the cumulativeLineChart adds a &#8220;display.y&#8221; property dynamically to data values in the series. However, it does not regenerate this property when new values are added to the series for a redraw. I don&#8217;t know of anyway to make it do this, although I&#8217;m new to NVD3.<\/p>\n<p>Do you really need a CumulativeLineChart, or would a normal line chart be sufficient? If so, I had to make the following changes to your code:<\/p>\n<ul>\n<li>Change from <strong>cumulativeLineChart to lineChart<\/strong><\/li>\n<li>Change from using 2 dimension arrays of data, to using <strong>objects of data (with x,y properties)<\/strong>\n<ul>\n<li>(I&#8217;m not familiar enough with NVD3 to say what data formats is expects. The 2D array obviously works for initial loads, but I think it fails to work for subsequent redraws. This is likely related to the same issue you are having with cumulativeLineChart. I thought changing to objects would fix cumulativeLineChart as well, but it didn&#8217;t seem to.)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>I also changed the following, although not as important:<\/p>\n<ul>\n<li>\n<p>Modified your getData function to <strong>create a new instance of Date<\/strong> to avoid unexpected consequences of sharing a reference as the date gets incremented.<\/p>\n<\/li>\n<li>\n<p>Modified the update interval function to generate new data in increments of days (not months) with y values in the same range as the getData function.<\/p>\n<\/li>\n<\/ul>\n<p>Here&#8217;s a working jsfiddle with those changes:<\/p>\n<ul>\n<li>http:\/\/jsfiddle.net\/kaliatech\/4TMMD\/<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>kaliatech Second Answer (after comment) I looked at source for cumulativeLineChart. You can see the display.y property get created during chart creation. It relies on a private method: &#8220;indexify&#8221;. If some derivative of that method was made public, then perhaps you could do something like chart.reindexify() before redrawing. As a temporary workaround, you could recreate [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7533","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7533"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7533\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}