
Many variants of diagrams
The open source solution "Chart.js" offers a total of six different chart types, each of which can be individually configured and allow direct user interaction.
Chart.js uses modern HTML5 and JavaScript technology and can be executed in a FileMaker web viewer. The generated charts are in SVG vector graphic format and can be freely scaled without loss of quality. The Charts.js website contains extensive documentation on how diagrams can also be designed interactively, so that, for example, clicking on a part of a diagram can open a FileMaker web viewer.Script can be started.
Encapsulate Chart.js in FileMaker
To be able to use the functions from the JavaScript library "Chart.js" in FileMaker, you must first install the current version of the Charts.js Library to your computer. The Chart.js library is already integrated in our sample solution, which you can download at the end of this article. We have modified the library contained there so that charts with negative values can also be displayed.
In our example solution, we have encapsulated the Chart.js library in a separate (global) field. The <> field therefore simply contains the source code of the entire "Chart.js" text file.
Diagram source as own FileMaker fields
If you download the entire "Chart.js" package, you will find some sample HTML files in the "samples" directory that can be used to display sample charts. For these files, which are required to display the chart, our FileMaker solution contains the global fields <> and <>, each of which provides the source code for the corresponding chart type. In the corresponding source codes, we have created placeholders for all values that we want to insert dynamically from FileMaker. We have inserted the following placeholders into the source code:
- {javascript} - Placeholder for Chart.js, in the area between
- {width} - Width of the diagram
- {height} - Height of the diagram
- {t1} - {t12} - Text labeling 1 to 12 for values 1 to 12
- {w1} - {w12} - Values 1 to 12
- {red}, {green}, {blue} - RGB color values for colors of the diagram
The HTML source code for displaying the diagram in a FileMaker web viewer is generated from these fields with the placeholders they contain.
Merge chart source and Chart.js
To finally display the chart in a FileMaker web viewer, our sample solution has an additional field called "xLay_Diagramm_Webviewer". The final chart code is generated in this field, which consists of the chart source code, the Chart.js and the dynamic data. After clicking on the register button [value 1], the following script is executed schematically:
Set field value [xLay_Diagram_Webviewer; Exchange (xGlo_Diagram; Placeholder; Fields/Data)]
Set variable [$$menuchart; Value: "Value 1"]
Write change data/query [suppress; without dialog box]
Refresh window [Delete join results, delete cache]
In the first script step, the HTML source code for the web viewer is generated from the fields for the chart source code, Chart.js and the dynamic data. The second script step sets a global Variablewhich indicates that the "Value 1" diagram is active and displayed. With the last two script steps we ensure that the data is saved and the current window is updated.
Show other chart types
In our example file, all the sub-scripts to be called up are in a script, which are called up via corresponding script parameters. The first two sub-scripts "chart_value_1" and "chart_value_2" update the chart after clicking on a corresponding tab button. The two sub-scripts "bar" and "line" can be used to switch the type of chart from bar to line chart.
In our example, a total of 12 values are always displayed, which is why the source codes have a correspondingly flat structure. Of course, it is also possible to display more than 12 values or to display several data series per diagram. In this case, you must design the replacement of the placeholders dynamically by using a placeholder for an entire data series row and building up the data series dynamically in the script. In our example, we limit ourselves to a flat structure with 12 values in a data series.
Download FileMaker sample database (.fmp12)
The sample database for this article is available in FileMaker 12 format (.fmp12) for FileMaker 12 to 14, the download is free of charge.
Video tutorial by Matt Petrowski on the topic
Matt Petrowski, in his capacity as an outstanding FileMaker developer, has published a video tutorial on the subject of "Diagrams with FileMaker and JavaScript". In the following video he shows the possibilities of diagrams with JavaScript in the FileMaker Webviewer in English.
By loading the video, you accept YouTube's privacy policy.
Learn more
Many thanks to Matt Petrowski and Nick Downie for this great solution!
How to transfer scripts from the sample file to your solution
Scripts can be easily transferred from one FileMaker solution to another via the clipboard. Simply open the dialog Manage scriptsSelect the desired script with the mouse and copy the script to the clipboard using the [Edit - Copy] menu or [Ctrl/Cmd-C] key combination. Then open the same dialog in the target solution and simply paste the previously copied script using the [Edit - Paste] menu command.
To transfer tables from the example file to your solution
Tables can be inserted into an existing solution in several ways. The easiest way is to import the Table via the [Import...] button in the dialog Manage database. All tables to be imported from the source solution can then be selected in a subsequent dialog. This method is therefore particularly suitable if several tables are to be imported at the same time. If only one table is to be imported, this can also be done via the clipboard like a script. If a table is to be imported together with its data, this can be done with the command [File > Import records > File]. In the import dialog, the target table New table must be specified.
How to transfer value lists from the example file to your solution
Value lists can be easily imported from one FileMaker solution to another via the clipboard. Simply open the dialog under [File/File > Manage > Value lists], select the desired value list and click on [Import]. Value list with the mouse and copy the value list to the clipboard using the [Edit - Copy] menu or the [Ctrl/Cmd-C] key combination. Then open the same dialog in the target solution and paste the previously copied value list using the [Edit - Paste] menu command.
How to transfer your own functions from the example file to your solution
In the [File > Manage > Custom functions...] dialog, click on the [Import] button and select the sample file. Select the desired custom functions in the following dialog and confirm the dialog. Please note that this function is only available in FileMaker Pro Advanced, but not in FileMaker Pro.

Markus Schall has been developing individual databases, interfaces and business applications based on Claris FileMaker since 1994. He is a Claris partner, FMM Award winner 2011 and developer of the ERP software gFM-Business. He is also a book author and founder of the M. Schall Publishers.




Many thanks for the simplified introduction. Everything works perfectly on my Mac with FM 18 and MacOS 10.15.1. I have updated Chart.js to version 2.9.1. In the Windows environment, however, the charts are only displayed in Internet Explorer. Any ideas?
Does the problem only occur in connection with FileMaker, or does it also not work in other browsers from a normal website?
Thank you very much for the great instructions and the sample database. Where I'm stuck: What do I need to change in the code to get a doughnut chart instead of a bar or line chart? If I simply replace "window.myBar = new Chart(ctx).Bar(barChartData, options);" with "window.myBar = new Chart(ctx).doughnut(barChartData, options);", unfortunately it doesn't work...
Hello and thank you for your interest! Just a guess: Maybe the data has to be prepared a little differently for the other chart type?