{"id":17268450,"date":"2023-12-11T14:48:23","date_gmt":"2023-12-11T14:48:23","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/pie-chart-fields\/"},"modified":"2023-12-11T14:52:08","modified_gmt":"2023-12-11T14:52:08","slug":"pie-chart-fields","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/pie-chart-fields\/","title":{"rendered":"Pie Chart Fields"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I&#8217;m making a calculator with a pie chart to show how housing affordability is largely a function of finance costs and taxes on taxes on taxes. It calls a Pie Chart in charts js, the canvas and values display, but I am having trouble adding more than two fields (pie chart is at the very bottom of my calculator page). The third and fourth fields mess up the chart (it becomes a solid field of one colour). Here is how I am adding data, field by field in the field holding custom values (all in dollars):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(function(){<br \/>setPieChartBlock(<br \/>&#8216;my_canvas&#8217;,<br \/>[<br \/>{label: &#8216;Land Cost&#8217;, value: fieldname41},<br \/>{label: &#8216;Land Cost&#8217;, value: fieldname41},<br \/>{label: &#8216;Land Appreciation&#8217;, value: fieldname56},<br \/>]<br \/>);<br \/>})()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But over in Charts.js I see they make a dataset and just call that: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">const DATA_COUNT = 5;<br \/>const NUMBER_CFG = {count: DATA_COUNT, min: 0, max: 100};<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">const data = {<br \/>labels: [&#8216;Red&#8217;, &#8216;Orange&#8217;, &#8216;Yellow&#8217;, &#8216;Green&#8217;, &#8216;Blue&#8217;],<br \/>datasets: [<br \/>{<br \/>label: &#8216;Dataset 1&#8217;,<br \/>data: Utils.numbers(NUMBER_CFG),<br \/>backgroundColor: Object.values(Utils.CHART_COLORS),<br \/>}<br \/>]<br \/>};<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Can you tell me what I may be misunderstanding? Does the pie calculate its own total (ie. 100%) from the fields a user adds, or does that need to be specified somewhere for the subsequent data fields to represent pie slices?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PS: I&#8217;m not sure where the mouseover display values of 10, 10, 4 are coming from, they should show the values from their respective fields and dollars before, no?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PPS: I show land cost 2x because the pie breaks anytime I add any other field with a dollar value sum from the subtotal fields on the right hand side of the calculator. <\/p>\n","protected":false},"template":"","class_list":["post-17268450","topic","type-topic","status-publish","hentry","topic-tag-values"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/17268450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":2,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/17268450\/revisions"}],"predecessor-version":[{"id":17268472,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/17268450\/revisions\/17268472"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=17268450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}