{"id":7540,"date":"2015-07-26T05:12:09","date_gmt":"2015-07-26T05:12:09","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/07\/26\/how-can-i-keep-tick-marks-from-repeating-when-i-have-a-small-number-of-dates-on-an-nvd3-chart-open-source-projects-novus-nvd3\/"},"modified":"2015-07-26T05:12:09","modified_gmt":"2015-07-26T05:12:09","slug":"how-can-i-keep-tick-marks-from-repeating-when-i-have-a-small-number-of-dates-on-an-nvd3-chart-open-source-projects-novus-nvd3","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/07\/26\/how-can-i-keep-tick-marks-from-repeating-when-i-have-a-small-number-of-dates-on-an-nvd3-chart-open-source-projects-novus-nvd3\/","title":{"rendered":"How can I keep tick marks from repeating when I have a small number of dates on an nvd3 chart-open source projects novus\/nvd3"},"content":{"rendered":"<p>The x axis likes to repeat dates when there are a limited number of dates. Please see this fiddle:<\/p>\n<p>http:\/\/jsfiddle.net\/skilesare\/bFfJ2\/1\/<\/p>\n<pre><code>nv.addGraph(function() {  \n\n    var data = fakeActivityByDate();\n\n    var chart = nv.models.lineChart();\n\n\n\n\nchart.xAxis\n       .axisLabel('Date')\n       .rotateLabels(-45)\n       .tickFormat(function(d) { return d3.time.format('%b %d')(new Date(d)); });\n\n   chart.yAxis\n       .axisLabel('Activity')\n       .tickFormat(d3.format('d'));\n\n   d3.select('#chart svg')\n       .datum(data)\n     .transition().duration(500)\n       .call(chart);\n\n   nv.utils.windowResize(function() { d3.select('#chart svg').call(chart) });\n\n   return chart;\n });\n\nfunction days(num) {\n  return num*60*60*1000*24\n}\n \/**************************************\n  * Simple test data generator\n  *\/\n\nfunction fakeActivityByDate() {\n   var lineData = [];\n   var y=0;\n   var start_date = new Date() - days(365); \/\/ one year ago\n\n   for (var i = 0; i &lt; 4; i++) {\n     lineData.push({x: new Date(start_date + days(i)), y: y});\n     y=y+Math.floor((Math.random()*10)-3);\n   }\n\n   return [\n     {\n       values: lineData,\n       key: 'Activity',\n       color: '#ff7f0e'\n     }\n   ];\n }`\n<\/code><\/pre>\n<p>If your screen is wide enough you will see dates repeated. If you sqeeze the window, the problem goes away.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The x axis likes to repeat dates when there are a limited number of dates. Please see this fiddle: http:\/\/jsfiddle.net\/skilesare\/bFfJ2\/1\/ nv.addGraph(function() { var data = fakeActivityByDate(); var chart = nv.models.lineChart(); chart.xAxis .axisLabel(&#8216;Date&#8217;) .rotateLabels(-45) .tickFormat(function(d) { return d3.time.format(&#8216;%b %d&#8217;)(new Date(d)); }); chart.yAxis .axisLabel(&#8216;Activity&#8217;) .tickFormat(d3.format(&#8216;d&#8217;)); d3.select(&#8216;#chart svg&#8217;) .datum(data) .transition().duration(500) .call(chart); nv.utils.windowResize(function() { d3.select(&#8216;#chart svg&#8217;).call(chart) }); return chart; [&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-7540","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7540","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=7540"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7540\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}