In this blog, I’m going to talk about Business Charts in detail and how you can create them from scratch.
Building Business Charts is one of the ways you can take advantage of the powerful charting capabilities in Dynamics NAV.
Please refer to my previous blog post (Building Charts in Microsoft Dynamics NAV 2013 R2) to know about different ways of building charts in NAV.
WHAT ARE BUSINESS CHARTS?
Business charts are based on Business Chart control add-in which is provided by the Microsoft.Dynamics.Nav.Client.BusinessChart.dll assembly. More details about Displaying the Charts using Chart control add-in here
As compared to other chart types, Business charts provide advanced functionalities such as:
- Displaying complex data that is calculated on a page.
- Allowing end users to filter data and drill down to the details from the chart
- Allowing dynamic filtering of data
- Being supported on Dynamics NAV Web client.
EXPLORE EXISTING BUSINESS CHARTS:
Out of the box, in the Cronus demo database, there are a few business charts available such as Trailing sales orders, Cash flow chart, Finance performance, Sales performance, Inventory performance etc.. These charts can be used on Role centers or along with pages.
For ex, In the Cronus demo database, when we login with President’s profile, we can view multiple business charts as shown below:
Tips:
- If you’re not able to see these charts on the President role center, you can add them by using Customize this page option.
- Once added, if there is nothing shown on these graphs, change the filters using Select Chart or Show buttons on these charts.
- When the chart is displayed, click on the chart to experience the drill down functionality.
- Experience interactive features using Period Length, group by, Start Date and other options on these charts.
- Each of these charts are nothing but a CardPart pages at the backend.
BUILDING BUSINESS CHARTS FROM SCRATCH
At the end of this blog, you will know how to build a simple Business chart which can be used as a factbox in the Item list page showing location wise Inventory. This chart updates automatically when you move to any particular line on the item list page.
Location wise Inventory Business Chart:
We need to mainly use Business Chart Buffer table (485) to build the business charts. This table holds chart related values and also has multiple functions pre-defined which can be used to build our chart on a page object.
Following objects are required to build Location wise Inventory Business Chart:
1. A Query to calculate Location wise remaining quantity for all the items
2. A Codeunit to use the above query result and prepare Business Chart Buffer table.
3. A Page to display the chart.
-> Design
1. Design a new Query object which shows Location wise remaining quantity for all the items. We will be using the query result as chart data.
a. Open Dynamics NAV development environment and click on Query and next click on New to design a new query
b. Specify the query DataItem and columns as shown below:
c. Save the query. (ex: ID-65000 and Name-Item qty. location wise)
d. Run the query (65000) to see location wise total quantity of items.
2. Design a new CodeUnit to populate the Business chart buffer table with the above query result.
a. In the Dynamics NAV development environment, click on Codeunit and next click on New to design a new Codeunit.
b. In the codeunit designer, click on View–> Globals–> Functions tab to create a new function in the Codeunit. Enter the function name as GenerateDataInventorybyLoc and click on Locals button to enter parameters and variables for the function as shown in the below image:
c. Now in the Codeunit designer you see an new function trigger called GenerateDataInventorybyLoc. Enter the code as shown in the below image. The in-line comments within the Codeunit explains more about each line of code:
d. Save the Codunit (ex: ID-65000 and Name-Items qty by loc. chart mgt.)
3. Design a new Page object to display the Business Chart.
a. In the Dynamics NAV development environment, click on Page and next click on New to design a new page object.
b. In the Page design wizard, Specify Table as Item and Page type as CardPart as shown below and click on Ok. Click on Finish to close the Page design wizard.
c. Insert a field in the page with name Chart and click on field properties button. Specify the ControlAddIn property for the Chart field as highlighted below. (You need to choose Microsoft.Dynamics.Nav.Client.BusinessChart control add-in)
d. In the page designer click on C/AL Code (F9) button to open the triggers. We will see additional triggers being added below for this control add-in field:
e. we’ll define a new function within this page. click on View–> Globals–> Functions tab to create a new function in the Codeunit. Enter the function name as UpdateChart and click on Locals button to enter variables for the function as shown in the below image:
f. Click on C/AL Code (F9) again to open triggers. Enter the Code as shown in the below image:
g. Save the page. (ex: ID-65000 and Name-Items Qty by location chart)
4. The Business chart is now ready to be displayed! Add it to the Item list page as a Page part
a. In the Dynamics NAV development environment, click on Page and find the Item List page. Click on Design and go to the last line of the page designer. Enter a new line as shown below:
b. click on Properties to open the Page Part properties and specify PagePartID and SubPageLink as shown below:
c. Save the Item List page.
5. Open/refresh your Item list page on the NAV Windows/Web client to see a factbox showing Location wise Inventory Chart. Select different items to see the graph change respectively.
The below Image shows the Item List page in Windows client:
IN MY NEXT BLOG:
I will explain how to drilldown to details by clicking on parts of a business chart.
Thanks for reading my blog. Feel free to leave a comment.