{"id":139,"date":"2015-09-19T17:50:50","date_gmt":"2015-09-19T17:50:50","guid":{"rendered":"http:\/\/blazingspider.com\/wp-demo\/?p=139"},"modified":"2015-09-19T19:39:30","modified_gmt":"2015-09-19T19:39:30","slug":"nvd3-js-sample-pie-chart","status":"publish","type":"post","link":"https:\/\/blazingspider.com\/wp-demo\/139\/nvd3-js-sample-pie-chart\/","title":{"rendered":"NVD3.js Sample: A Pie Chart"},"content":{"rendered":"<p>The following Pie Chart, drawn by NVD3.js library:<\/p>\n<p><!--more--><\/p>\n<div id='chart'>Regular pie chart\r\n  <svg style='height:500px;width:400px'> <\/svg>\r\n<\/div>\r\n<div id='chart2'>Donut chart\r\n  <svg style='height:500px;width:400px'> <\/svg>\r\n<\/div>\r\n<style>\r\n.nvtooltip {\r\n   max-width: 150px;\r\n}\r\n<\/style>\r\n\r\n<script type=\"text\/javascript\">\r\nwindow.onload = function () {\r\n\r\n\/\/Regular pie chart example\r\nnv.addGraph(function() {\r\n  var chart = nv.models.pieChart()\r\n      .x(function(d) { return d.label })\r\n      .y(function(d) { return d.value })\r\n      .showLabels(true);\r\n\r\n    d3.select(\"#chart svg\")\r\n        .datum(exampleData())\r\n        .transition().duration(350)\r\n        .call(chart);\r\n\r\n  return chart;\r\n});\r\n\r\n\/\/Donut chart example\r\nnv.addGraph(function() {\r\n  var chart = nv.models.pieChart()\r\n      .x(function(d) { return d.label })\r\n      .y(function(d) { return d.value })\r\n      .showLabels(true)     \/\/Display pie labels\r\n      .labelThreshold(.05)  \/\/Configure the minimum slice size for labels to show up\r\n      .labelType(\"percent\") \/\/Configure what type of data to show in the label. Can be \"key\", \"value\" or \"percent\"\r\n      .donut(true)          \/\/Turn on Donut mode. Makes pie chart look tasty!\r\n      .donutRatio(0.35)     \/\/Configure how big you want the donut hole size to be.\r\n      ;\r\n\r\n    d3.select(\"#chart2 svg\")\r\n        .datum(exampleData())\r\n        .transition().duration(350)\r\n        .call(chart);\r\n\r\n  return chart;\r\n});\r\n\r\n\/\/Pie chart example data. Note how there is only a single array of key-value pairs.\r\nfunction exampleData() {\r\n  return  [\r\n      { \r\n        \"label\": \"One\",\r\n        \"value\" : 29.765957771107\r\n      } , \r\n      { \r\n        \"label\": \"Two\",\r\n        \"value\" : 0\r\n      } , \r\n      { \r\n        \"label\": \"Three\",\r\n        \"value\" : 32.807804682612\r\n      } , \r\n      { \r\n        \"label\": \"Four\",\r\n        \"value\" : 196.45946739256\r\n      } , \r\n      { \r\n        \"label\": \"Five\",\r\n        \"value\" : 0.19434030906893\r\n      } , \r\n      { \r\n        \"label\": \"Six\",\r\n        \"value\" : 98.079782601442\r\n      } , \r\n      { \r\n        \"label\": \"Seven\",\r\n        \"value\" : 13.925743130903\r\n      } , \r\n      { \r\n        \"label\": \"Eight\",\r\n        \"value\" : 5.1387322875705\r\n      }\r\n    ];\r\n}\r\n}\r\n<\/script>\n<p>Using our plugin, named <em>Blazing Charts<\/em>, I added the following shortcode to this post:<\/p>\n<pre>(left-bracket)BlazingChart charttype=\"d3\" source=\"nvd3-js-pie-chart-sample\" options=\"nvd3\"(right bracket)<\/pre>\n<p>The first parameter specifies which charting library is used. The second parameter is the slug of a Custom Post Type, named <em>Chart Snippets<\/em>, introduced by that plugin. The third parameter can be a comma-separated list of auxiliary libraries loaded after the main one. For drawing these pie charts, NVD3.js is used.<\/p>\n<p>The source of the script for the drawing is added as plain text to a Chart Snippet. The content of the chart snippet for the above chart is as following:<\/p>\n<pre lang=\"js\" toggle=\"no\">&lt;div id='chart'&gt;Regular pie chart\r\n  &lt;svg style='height:500px;width:400px'&gt; &lt;\/svg&gt;\r\n&lt;\/div&gt;\r\n&lt;div id='chart2'&gt;Donut chart\r\n  &lt;svg style='height:500px;width:400px'&gt; &lt;\/svg&gt;\r\n&lt;\/div&gt;\r\n&lt;style&gt;\r\n.nvtooltip {\r\n   max-width: 150px;\r\n}\r\n&lt;\/style&gt;\r\n\r\n&lt;script type=\"text\/javascript\"&gt;\r\nwindow.onload = function () {\r\n\r\n\/\/Regular pie chart example\r\nnv.addGraph(function() {\r\n  var chart = nv.models.pieChart()\r\n      .x(function(d) { return d.label })\r\n      .y(function(d) { return d.value })\r\n      .showLabels(true);\r\n\r\n    d3.select(\"#chart svg\")\r\n        .datum(exampleData())\r\n        .transition().duration(350)\r\n        .call(chart);\r\n\r\n  return chart;\r\n});\r\n\r\n\/\/Donut chart example\r\nnv.addGraph(function() {\r\n  var chart = nv.models.pieChart()\r\n      .x(function(d) { return d.label })\r\n      .y(function(d) { return d.value })\r\n      .showLabels(true)     \/\/Display pie labels\r\n      .labelThreshold(.05)  \/\/Configure the minimum slice size for labels to show up\r\n      .labelType(\"percent\") \/\/Configure what type of data to show in the label. Can be \"key\", \"value\" or \"percent\"\r\n      .donut(true)          \/\/Turn on Donut mode. Makes pie chart look tasty!\r\n      .donutRatio(0.35)     \/\/Configure how big you want the donut hole size to be.\r\n      ;\r\n\r\n    d3.select(\"#chart2 svg\")\r\n        .datum(exampleData())\r\n        .transition().duration(350)\r\n        .call(chart);\r\n\r\n  return chart;\r\n});\r\n\r\n\/\/Pie chart example data. Note how there is only a single array of key-value pairs.\r\nfunction exampleData() {\r\n  return  [\r\n      { \r\n        \"label\": \"One\",\r\n        \"value\" : 29.765957771107\r\n      } , \r\n      { \r\n        \"label\": \"Two\",\r\n        \"value\" : 0\r\n      } , \r\n      { \r\n        \"label\": \"Three\",\r\n        \"value\" : 32.807804682612\r\n      } , \r\n      { \r\n        \"label\": \"Four\",\r\n        \"value\" : 196.45946739256\r\n      } , \r\n      { \r\n        \"label\": \"Five\",\r\n        \"value\" : 0.19434030906893\r\n      } , \r\n      { \r\n        \"label\": \"Six\",\r\n        \"value\" : 98.079782601442\r\n      } , \r\n      { \r\n        \"label\": \"Seven\",\r\n        \"value\" : 13.925743130903\r\n      } , \r\n      { \r\n        \"label\": \"Eight\",\r\n        \"value\" : 5.1387322875705\r\n      }\r\n    ];\r\n}\r\n}\r\n&lt;\/script&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following Pie Chart, drawn by NVD3.js library:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,17],"tags":[20],"class_list":["post-139","post","type-post","status-publish","format-standard","hentry","category-chart-libraries","category-d3-js","tag-d3-js"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>NVD3.js Sample: A Pie Chart - WordPress Demo<\/title>\n<meta name=\"description\" content=\"Wordpress plugin &quot;Blazing Charts&quot; helps you to use D3.js Charting Libraries. It saves the snippets of charts in database as a post type.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blazingspider.com\/wp-demo\/139\/nvd3-js-sample-pie-chart\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"NVD3.js Sample: A Pie Chart - WordPress Demo\" \/>\n<meta property=\"og:description\" content=\"Wordpress plugin &quot;Blazing Charts&quot; helps you to use D3.js Charting Libraries. It saves the snippets of charts in database as a post type.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blazingspider.com\/wp-demo\/139\/nvd3-js-sample-pie-chart\/\" \/>\n<meta property=\"og:site_name\" content=\"WordPress Demo\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/blazingspider\" \/>\n<meta property=\"article:published_time\" content=\"2015-09-19T17:50:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-09-19T19:39:30+00:00\" \/>\n<meta name=\"author\" content=\"massoud Shakeri\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@BlazingSpider\" \/>\n<meta name=\"twitter:site\" content=\"@BlazingSpider\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"massoud Shakeri\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blazingspider.com\/wp-demo\/139\/nvd3-js-sample-pie-chart\/\",\"url\":\"https:\/\/blazingspider.com\/wp-demo\/139\/nvd3-js-sample-pie-chart\/\",\"name\":\"NVD3.js Sample: A Pie Chart - WordPress Demo\",\"isPartOf\":{\"@id\":\"https:\/\/blazingspider.com\/wp-demo\/#website\"},\"datePublished\":\"2015-09-19T17:50:50+00:00\",\"dateModified\":\"2015-09-19T19:39:30+00:00\",\"author\":{\"@id\":\"https:\/\/blazingspider.com\/wp-demo\/#\/schema\/person\/78f615e83cf347ec4b200f825ba2fecd\"},\"description\":\"Wordpress plugin \\\"Blazing Charts\\\" helps you to use D3.js Charting Libraries. It saves the snippets of charts in database as a post type.\",\"breadcrumb\":{\"@id\":\"https:\/\/blazingspider.com\/wp-demo\/139\/nvd3-js-sample-pie-chart\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blazingspider.com\/wp-demo\/139\/nvd3-js-sample-pie-chart\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blazingspider.com\/wp-demo\/139\/nvd3-js-sample-pie-chart\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blazingspider.com\/wp-demo\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"NVD3.js Sample: A Pie Chart\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blazingspider.com\/wp-demo\/#website\",\"url\":\"https:\/\/blazingspider.com\/wp-demo\/\",\"name\":\"WordPress Demo\",\"description\":\"Blazing Spider WordPress Demo\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blazingspider.com\/wp-demo\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blazingspider.com\/wp-demo\/#\/schema\/person\/78f615e83cf347ec4b200f825ba2fecd\",\"name\":\"massoud Shakeri\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blazingspider.com\/wp-demo\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3f3d05ee01040cb3ff9bd45b9a45027330209a9a0807f4ad9b195ec7f678f333?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3f3d05ee01040cb3ff9bd45b9a45027330209a9a0807f4ad9b195ec7f678f333?s=96&d=mm&r=g\",\"caption\":\"massoud Shakeri\"},\"sameAs\":[\"http:\/\/blazingspider.com\"],\"url\":\"https:\/\/blazingspider.com\/wp-demo\/author\/massoudshakeri\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"NVD3.js Sample: A Pie Chart - WordPress Demo","description":"Wordpress plugin \"Blazing Charts\" helps you to use D3.js Charting Libraries. It saves the snippets of charts in database as a post type.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blazingspider.com\/wp-demo\/139\/nvd3-js-sample-pie-chart\/","og_locale":"en_US","og_type":"article","og_title":"NVD3.js Sample: A Pie Chart - WordPress Demo","og_description":"Wordpress plugin \"Blazing Charts\" helps you to use D3.js Charting Libraries. It saves the snippets of charts in database as a post type.","og_url":"https:\/\/blazingspider.com\/wp-demo\/139\/nvd3-js-sample-pie-chart\/","og_site_name":"WordPress Demo","article_publisher":"https:\/\/www.facebook.com\/blazingspider","article_published_time":"2015-09-19T17:50:50+00:00","article_modified_time":"2015-09-19T19:39:30+00:00","author":"massoud Shakeri","twitter_card":"summary_large_image","twitter_creator":"@BlazingSpider","twitter_site":"@BlazingSpider","twitter_misc":{"Written by":"massoud Shakeri","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/blazingspider.com\/wp-demo\/139\/nvd3-js-sample-pie-chart\/","url":"https:\/\/blazingspider.com\/wp-demo\/139\/nvd3-js-sample-pie-chart\/","name":"NVD3.js Sample: A Pie Chart - WordPress Demo","isPartOf":{"@id":"https:\/\/blazingspider.com\/wp-demo\/#website"},"datePublished":"2015-09-19T17:50:50+00:00","dateModified":"2015-09-19T19:39:30+00:00","author":{"@id":"https:\/\/blazingspider.com\/wp-demo\/#\/schema\/person\/78f615e83cf347ec4b200f825ba2fecd"},"description":"Wordpress plugin \"Blazing Charts\" helps you to use D3.js Charting Libraries. It saves the snippets of charts in database as a post type.","breadcrumb":{"@id":"https:\/\/blazingspider.com\/wp-demo\/139\/nvd3-js-sample-pie-chart\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blazingspider.com\/wp-demo\/139\/nvd3-js-sample-pie-chart\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blazingspider.com\/wp-demo\/139\/nvd3-js-sample-pie-chart\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blazingspider.com\/wp-demo\/"},{"@type":"ListItem","position":2,"name":"NVD3.js Sample: A Pie Chart"}]},{"@type":"WebSite","@id":"https:\/\/blazingspider.com\/wp-demo\/#website","url":"https:\/\/blazingspider.com\/wp-demo\/","name":"WordPress Demo","description":"Blazing Spider WordPress Demo","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blazingspider.com\/wp-demo\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blazingspider.com\/wp-demo\/#\/schema\/person\/78f615e83cf347ec4b200f825ba2fecd","name":"massoud Shakeri","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blazingspider.com\/wp-demo\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/3f3d05ee01040cb3ff9bd45b9a45027330209a9a0807f4ad9b195ec7f678f333?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3f3d05ee01040cb3ff9bd45b9a45027330209a9a0807f4ad9b195ec7f678f333?s=96&d=mm&r=g","caption":"massoud Shakeri"},"sameAs":["http:\/\/blazingspider.com"],"url":"https:\/\/blazingspider.com\/wp-demo\/author\/massoudshakeri\/"}]}},"_links":{"self":[{"href":"https:\/\/blazingspider.com\/wp-demo\/wp-json\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blazingspider.com\/wp-demo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blazingspider.com\/wp-demo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blazingspider.com\/wp-demo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blazingspider.com\/wp-demo\/wp-json\/wp\/v2\/comments?post=139"}],"version-history":[{"count":3,"href":"https:\/\/blazingspider.com\/wp-demo\/wp-json\/wp\/v2\/posts\/139\/revisions"}],"predecessor-version":[{"id":147,"href":"https:\/\/blazingspider.com\/wp-demo\/wp-json\/wp\/v2\/posts\/139\/revisions\/147"}],"wp:attachment":[{"href":"https:\/\/blazingspider.com\/wp-demo\/wp-json\/wp\/v2\/media?parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blazingspider.com\/wp-demo\/wp-json\/wp\/v2\/categories?post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blazingspider.com\/wp-demo\/wp-json\/wp\/v2\/tags?post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}