While talking about design patterns, we often came upon a different category of code solutions. Useful, reusable, good practice code solutions which are just not design patterns. They might be APIs, they might be mini-features, new platform functionality, or services.
We don’t want to throw away those good ideas. On the other side, they do not belong to design patterns.
Hence, a chapter called “Recipes – The NAV C/AL Cookbook” was born, as a separate section on the Dynamics Community NAV Patterns Wiki. We hope you’ll find it as useful as we did. And find below one of the first articles on this new section. Note that we’re still using the “Meet the pattern – Know the pattern” format, just to keep an uniform approach on all articles, for the moment.
Creating Custom Charts
by Nikola Kukrika at Microsoft Development Center Copenhagen
Meet the Pattern
The goal of this pattern is to enable you to:
- Use charts in the web client.
- Create charts with custom functionality.
Know the Pattern
This pattern enables you to implement a business chart (Specific Chart type) in a way that is maintainable and reusable on other pages. This also enables you to provide specific functionality that is not possible with the Generic Chart type and it enables you to show charts in the web client.
Example of the same chart in the Microsoft Dynamics NAV Windows client:
The most obvious differences in chart rendering in the two clients are: Slightly different line heights, slightly different chart height, legends in web-client charts can be used as toggle filters to show/hide groups (this is not possible in the win client).
Add-in Buffer Table
This table is used to encapsulate the logic of the Business Chart Add-in. The table handles the following logic:
- Storing chart values and conversion from .NET to C/AL and vice versa
- Handling of captions: We must use C/AL to provide multilanguage text in add-ins. In addition, the multilanguage text must be encapsulated in a single place, because we pass/read the same dataset from/to the add-in.
- DrillDown logic
- Other helper data related functions, for displaying date, periods, etc.
Note: It is recommended that you reuse the Business Chart Buffer table (485) as a buffer table or extend. It is a generic table which should cover most of the use cases. Implement a new buffer table only if this table does not meet your needs.
The CardPart page hosts the Business Chart add-in and must use the add-in buffer table as a source table.
On the page, you must implement the following triggers:
- AddInReady – Executed when the page is done rendering. Used to initialize the add-in.
- DataPointClicked – Single-click on an element on the chart.
- DataPointDoubleClicked – Double-click on an element on the chart
The CardPart usually contains a StatusText variable to provide more information about the chart or dataset and a set of actions to control the chart.
The most commonly used actions are: … Read more on NAV Wiki…