{"id":5463,"date":"2023-09-10T16:33:46","date_gmt":"2023-09-10T14:33:46","guid":{"rendered":"https:\/\/gpmfactory.com\/?p=5463"},"modified":"2023-09-10T16:33:46","modified_gmt":"2023-09-10T14:33:46","slug":"combined-apex-chart-with-orders-table","status":"publish","type":"post","link":"https:\/\/gpmfactory.com\/index.php\/2023\/09\/10\/combined-apex-chart-with-orders-table\/","title":{"rendered":"Combined APEX chart with ORDERS table"},"content":{"rendered":"\n<p>This demo is base on the standard demo tables ORDERS et ORDER_ITEMS. <br>The goal is to produce a chart with a monthly amount stacked with variance and a average monthly amount.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"492\" src=\"https:\/\/gpmfactory.com\/wp-content\/uploads\/2023\/09\/image-6-1024x492.png\" alt=\"\" class=\"wp-image-5465\" srcset=\"https:\/\/gpmfactory.com\/wp-content\/uploads\/2023\/09\/image-6-1024x492.png 1024w, https:\/\/gpmfactory.com\/wp-content\/uploads\/2023\/09\/image-6-300x144.png 300w, https:\/\/gpmfactory.com\/wp-content\/uploads\/2023\/09\/image-6-768x369.png 768w, https:\/\/gpmfactory.com\/wp-content\/uploads\/2023\/09\/image-6-1536x738.png 1536w, https:\/\/gpmfactory.com\/wp-content\/uploads\/2023\/09\/image-6-2048x984.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Build a combined chart and and two series from the tow following queries<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Statement 1: implemented as a Stacked bar serie<\/h4>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>select mm, b.mnt, 'mnt' serie from<br>(<br>select trunc(order_datetime,'MM') mm,<br>sum((unit_price *quantity)) mnt,<br>trunc(variance((unit_price *quantity)),2) vari<br>from orders d,<br>order_items i<br>where i.order_id = d.order_id<br>group by trunc(order_datetime,'MM')<br>order by 1<br>) b<br>UNION<br>select mm, b.mnt , 'variance' serie from<br>(<br>select trunc(order_datetime,'MM') mm,<br>trunc(variance((unit_price *quantity)),2) mnt<br>from orders d,<br>order_items i<br>where i.order_id = d.order_id<br>group by trunc(order_datetime,'MM')<br>order by 1<br>) b<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Statement 2: implemented as a line serie<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>select b.mm,a.avgi, b.mnt, b.vari from<br>( select trunc(avg(mnt),2) avgi<br>from (<br>select trunc(order_datetime,'MM') mm,<br>sum((unit_price *quantity)) mnt<br>from orders d,<br>order_items i<br>where i.order_id = d.order_id<br>group by trunc(order_datetime,'MM')<br>)<br>) a,<br>(<br>select trunc(order_datetime,'MM') mm,<br>sum((unit_price *quantity)) mnt,<br>trunc(variance((unit_price *quantity)),2) vari<br>from orders d,<br>order_items i<br>where i.order_id = d.order_id<br>group by trunc(order_datetime,'MM')<br>order by 1<br>) b<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"424\" src=\"https:\/\/gpmfactory.com\/wp-content\/uploads\/2023\/09\/image-5-1024x424.png\" alt=\"\" class=\"wp-image-5464\" srcset=\"https:\/\/gpmfactory.com\/wp-content\/uploads\/2023\/09\/image-5-1024x424.png 1024w, https:\/\/gpmfactory.com\/wp-content\/uploads\/2023\/09\/image-5-300x124.png 300w, https:\/\/gpmfactory.com\/wp-content\/uploads\/2023\/09\/image-5-768x318.png 768w, https:\/\/gpmfactory.com\/wp-content\/uploads\/2023\/09\/image-5-1536x636.png 1536w, https:\/\/gpmfactory.com\/wp-content\/uploads\/2023\/09\/image-5.png 1946w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>This demo is base on the standard demo tables ORDERS et ORDER_ITEMS. The goal is to produce a chart with a monthly amount stacked&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"ppma_author":[150],"class_list":["post-5463","post","type-post","status-publish","format-standard","hentry","category-non-classe"],"authors":[{"term_id":150,"user_id":1,"is_guest":0,"slug":"admin8700","display_name":"Patrick","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/209d5ed69b74d288390621ab4c1d3773?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/gpmfactory.com\/index.php\/wp-json\/wp\/v2\/posts\/5463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gpmfactory.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gpmfactory.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gpmfactory.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gpmfactory.com\/index.php\/wp-json\/wp\/v2\/comments?post=5463"}],"version-history":[{"count":1,"href":"https:\/\/gpmfactory.com\/index.php\/wp-json\/wp\/v2\/posts\/5463\/revisions"}],"predecessor-version":[{"id":5466,"href":"https:\/\/gpmfactory.com\/index.php\/wp-json\/wp\/v2\/posts\/5463\/revisions\/5466"}],"wp:attachment":[{"href":"https:\/\/gpmfactory.com\/index.php\/wp-json\/wp\/v2\/media?parent=5463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gpmfactory.com\/index.php\/wp-json\/wp\/v2\/categories?post=5463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gpmfactory.com\/index.php\/wp-json\/wp\/v2\/tags?post=5463"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/gpmfactory.com\/index.php\/wp-json\/wp\/v2\/ppma_author?post=5463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}