{"id":4100,"date":"2016-05-11T12:50:51","date_gmt":"2016-05-11T12:50:51","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=4100"},"modified":"2016-05-11T12:50:51","modified_gmt":"2016-05-11T12:50:51","slug":"d3-fixing-clipped-charts","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/d3-fixing-clipped-charts\/","title":{"rendered":"D3: Fixing clipped charts"},"content":{"rendered":"<p>If you make a chart in D3, you can get issues like this, where the axes get clipped:<\/p>\n<p><img alt='' class='alignnone size-full wp-image-4103' src='http:\/\/172.104.26.128\/wp-content\/uploads\/2016\/05\/img_5733297b2e45d.png' \/><\/p>\n<p>To fix the spacing between the charts, I would add space to the HTML element surrounding the chart. To fix the clipping inside, you need margin inside the chart &#8211; this is why all the D3 examples define a bounding box like so:<\/p>\n<pre lang=\"javascript\">\nlet margin = {top: 0, right: 0, bottom: 25, left: 0},\n    width = 200 - margin.left - margin.right,\n    height = 60 - margin.top - margin.bottom;\n<\/pre>\n<p>If you&#8217;ve done what most people have done, and copied existing examples, you should be able to just make this change:<br \/>\nlet margin = {top: 0, right: 5, bottom: 25, left: 5},<br \/>\n    width = 200 &#8211; margin.left &#8211; margin.right,<br \/>\n    height = 60 &#8211; margin.top &#8211; margin.bottom;<\/p>\n<p>And you&#8217;ll get a working chart:<br \/>\n<img alt='' class='alignnone size-full wp-image-4102' src='http:\/\/172.104.26.128\/wp-content\/uploads\/2016\/05\/img_5733292b8a32a.png' \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fixing alignment issues in D3<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[9],"tags":[136,138,302],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4100"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=4100"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4100\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=4100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=4100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=4100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}