{"id":11969,"date":"2019-08-09T17:37:28","date_gmt":"2019-08-09T17:37:28","guid":{"rendered":"https:\/\/www.directimpactsolutions.com\/?p=11969"},"modified":"2023-05-22T19:16:54","modified_gmt":"2023-05-22T19:16:54","slug":"google-chart-and-filemaker-api","status":"publish","type":"post","link":"https:\/\/www.directimpactsolutions.com\/en\/google-chart-and-filemaker-api\/","title":{"rendered":"Google Chart and FileMaker API"},"content":{"rendered":"<h3 class=\"wp-block-heading\">Integrating a Google Chart API with a FileMaker Solution<\/h3><p>A Google chart API can be integrated easily with FileMaker Pro using just the WebViewer. This simple approach can be accomplished in minutes and has few moving parts.<\/p><p>First, <a href=\"http:\/\/developers.google.com\/chart\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a> is the wide array of Google charts available. There are simple charts like bar graphs and pie charts, combination charts that show both line and bar graph data, and even advanced charts that show animation or maps.<\/p><p>This article has a video and a sample file to show the \u201cHello, World!\u201d program and demonstrate integration of the simplest chart. We start by taking code directly from Google,\u00a0paste it into a text field in FileMaker, and use just that field in a WebViewer. Just like that, we have a Google chart data that we can update manually!<\/p><pre class=\"wp-block-code\"><code>&lt;html&gt;\n  &lt;head&gt;\n   &lt;script type=\"text\/javascript\" src=\"https:\/\/www.gstatic.com\/charts\/loader.js\"&gt;&lt;\/script&gt;\n   &lt;script type=\"text\/javascript\"&gt;\n      google.charts.load('current', {'packages':&#91;'gauge']});\n      google.charts.setOnLoadCallback(drawChart);\n\n      function drawChart() {\n\n        var data = google.visualization.arrayToDataTable(&#91;\n          &#91;'Label', 'Value'],\n          &#91;'Memory', 80],\n          &#91;'CPU', 55],\n          &#91;'Network', 68]\n        ]);\n\n        var options = {\n          width: 400, height: 120,\n          redFrom: 90, redTo: 100,\n          yellowFrom:75, yellowTo: 90,\n          minorTicks: 5\n        };\n\n        var chart = new google.visualization.Gauge(document.getElementById('chart_div'));\n\n        chart.draw(data, options);\n\n        setInterval(function() {\n          data.setValue(0, 1, 40 + Math.round(60 * Math.random()));\n          chart.draw(data, options);\n        }, 13000);\n        setInterval(function() {\n          data.setValue(1, 1, 40 + Math.round(60 * Math.random()));\n          chart.draw(data, options);\n        }, 5000);\n        setInterval(function() {\n          data.setValue(2, 1, 60 + Math.round(20 * Math.random()));\n          chart.draw(data, options);\n        }, 26000);\n      }\n    &lt;\/script&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n    &lt;div id=\"chart_div\" style=\"width: 400px; height: 120px;\"&gt;&lt;\/div&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre><p>Notice that there are three code sections we need to know about to integrate with FileMaker. These are the top part that defines the language (HTML) and names the Javascript library on Google.<\/p><p>The second part is the actual chart data. This starts with&nbsp;<em>var data =<\/em>&nbsp; and you can see the lines that set values for Memory, CPU and Network. That is the part we can populate with data in your FileMaker database.<\/p><p>The last part is where we select which type of chart to draw \u2013 in this case that\u2019s the line that includes&nbsp;<em>google.visualization.Gauge<\/em><\/p><p>We also see some code that adds a randomizer to animate the chart. This makes it look like gauges in a car, where we can see values change. For our use, we don\u2019t need that code, so it\u2019s easy to remove. The rest of this section has code that defines the size of the chart to draw, and this should match the size of the WebViewer on your FileMaker layout.<\/p><p>To integrate this into FileMaker, we break out these three sections to three fields in a table. We then modify our WebViewer to join these three fields together.<\/p><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"670\" height=\"294\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API.png\" alt=\"\" class=\"wp-image-11970\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API.png 670w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-300x132.png 300w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-600x263.png 600w\" sizes=\"auto, (max-width: 670px) 100vw, 670px\" \/><\/figure><figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-2.png\" alt=\"\" class=\"wp-image-11972\" width=\"672\" height=\"632\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-2.png 1024w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-2-300x282.png 300w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-2-768x722.png 768w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-2-600x564.png 600w\" sizes=\"auto, (max-width: 672px) 100vw, 672px\" \/><\/figure><p>The last step is to write a script that gets whatever data you want to chart in your database. We\u2019ll use it to populate the middle field, called Chart Data in this example.<\/p><p>Note that\u00a0Google Chart\u00a0requires that each line needs to be formatted in a specific way, with square brackets, single quotes, and a comma, like this:<\/p><p>[\u2018ABC Tech\u2019,100],<\/p><p>[\u2018XYZ Systems\u2019,375],<\/p><p>[\u2018AppWorks\u2019,227],<\/p><p>The script will loop through the records, setting the value of a script parameter as we go, and then setting the field with the resulting chart data. There are probably many ways to do this, such as with JSON functions, but this way seemed straightforward to me. To make the code easier to write inside of the Loop, I defined script variables with the same punctuation as we used for the square brackets.<\/p><figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-3.png\" alt=\"\" class=\"wp-image-11974\" width=\"673\" height=\"424\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-3.png 1024w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-3-300x189.png 300w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-3-768x484.png 768w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-3-600x378.png 600w\" sizes=\"auto, (max-width: 673px) 100vw, 673px\" \/><\/figure><p>This is the code for line 10. I am using the List() function to build each line as we go, which is a very simple way to do this. Then for each line, I use the $pre&nbsp; $mid and $post variables to make it easier to read. The two bits of data pulled from my database are the name of the company and the invoice total.<\/p><pre class=\"wp-block-code\"><code>List ( \n  $data ; \n  $pre &amp; Invoices::Company &amp; $mid &amp;  \",\" &amp; Invoices::Total &amp; $post \n)<\/code><\/pre><p>Once that is done, you can call the script and see the chart.<\/p><figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-4.png\" alt=\"\" class=\"wp-image-11976\" width=\"679\" height=\"393\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-4.png 1024w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-4-300x174.png 300w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-4-768x445.png 768w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-4-600x347.png 600w\" sizes=\"auto, (max-width: 679px) 100vw, 679px\" \/><\/figure><p>One of my favorite aspects of this is that if you go into this line of code:<\/p><pre class=\"wp-block-code\"><code>var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));<\/code><\/pre><p>You can change the word ColumnChart to BarChart or PieChart or LineChart and it works. (This is very satisfying to try!)<\/p><p>I hope you have fun using the Google Chart API with your FileMaker database.\u00a0If you have questions about the content in this article, feel free to <a href=\"http:\/\/directimpactsolutions.com\/en\/contact-us\/\">contact us<\/a>!<\/p><hr class=\"wp-block-separator has-alpha-channel-opacity\" style=\"margin-top:var(--wp--preset--spacing--70);margin-bottom:var(--wp--preset--spacing--70)\"\/><p class=\"has-small-font-size\"><em>*This article was originally written for AppWorks, which has since joined Direct Impact Solutions. This article is intended for informative purposes only. To the best of our knowledge, this information is accurate as of the date of publication.<\/em><\/p>","protected":false},"excerpt":{"rendered":"<p>Integrating a Google Chart API with a FileMaker Solution A Google chart API can be integrated easily with FileMaker Pro using just the WebViewer. This simple approach can be accomplished in minutes and has few moving parts. First, here is the wide array of Google charts available. There are simple charts like bar graphs and &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/www.directimpactsolutions.com\/en\/google-chart-and-filemaker-api\/\"> <span class=\"screen-reader-text\">Google Chart and FileMaker API<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":6,"featured_media":11979,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"","footnotes":""},"categories":[29],"tags":[228,39,278],"class_list":["post-11969","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-low-code","tag-api","tag-filemaker","tag-google-chart"],"uagb_featured_image_src":{"full":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API.jpg",2000,1000,false],"thumbnail":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-150x150.jpg",150,150,true],"medium":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-300x150.jpg",300,150,true],"medium_large":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-768x384.jpg",768,384,true],"large":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-1024x512.jpg",1024,512,true],"1536x1536":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-1536x768.jpg",1536,768,true],"2048x2048":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API.jpg",2000,1000,false],"woocommerce_thumbnail":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-300x300.jpg",300,300,true],"woocommerce_single":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-600x300.jpg",600,300,true],"woocommerce_gallery_thumbnail":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Google-Chart-API-100x100.jpg",100,100,true]},"uagb_author_info":{"display_name":"Direct Impact Solutions","author_link":"https:\/\/www.directimpactsolutions.com\/en\/author\/direct-impact-solutions\/"},"uagb_comment_info":0,"uagb_excerpt":"Integrating a Google Chart API with a FileMaker Solution A Google chart API can be integrated easily with FileMaker Pro using just the WebViewer. This simple approach can be accomplished in minutes and has few moving parts. First, here is the wide array of Google charts available. There are simple charts like bar graphs and&hellip;","_links":{"self":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts\/11969","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/comments?post=11969"}],"version-history":[{"count":4,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts\/11969\/revisions"}],"predecessor-version":[{"id":21020,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts\/11969\/revisions\/21020"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/media\/11979"}],"wp:attachment":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/media?parent=11969"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/categories?post=11969"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/tags?post=11969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}