How to Create Graph and Chart in Ax 2012


Description:-

Microsoft Dynamics AX 2012 has integrated support for Microsoft .NET charts, easily managed via X++. 
The Microsoft .NET team has extended the .NET API by introducing a Chart control.Microsoft Dynamics Client enables simple use of this control by creating a new X++ wrapper class for the MSChart control: Graphics.The Microsoft Dynamics Client has introduced a new companion control for the MSChart control: The Chart Toolbar control.

With the Graphics class, an X++ developer can easily display their data graphical manner, without the need to utilize and understand the low-level .NET charting API. Simply utilize the Graphics class to initialize a chart with default display values, call a single "add data" API and then call Update to display the chart. In most cases, the developer will also want to provide the end user with the ability to manipulate the chart at runtime. In those cases, the developer will add the new Chart Toolbar to his form, and pass the toolbar an instance of the chart to be manipulated. That's it. An example use of charting can be found in the Tutorial_Form_Graphics form.

Start by adding Two Managed Controls to your form. One to host the Chart Control, the other to Host the Chart Toolbar 

For the purposes of this example name the chart control instance is "GraphControl"

Assembly: System.Windows.Forms
Control:  System.Windows.Forms.DataVisualization.Charting.Chart

Assembly: Microsoft.Dynamics.AX.Framework.Client.Controls
Control: Microsoft.Dynamics.AX.Framework.Client.Controls.ChartToolBar

For your Example I have Created Purchase Order table and based on table data I have display graph.
Follow this Step to Create Graph and Chart Control in your Form.

Step 1: Create table from AOT (Application Object Tree) Node and Name it “A_PurchaseOrder”.

1)      Expand AOT Node.
2)      Open Data Dictionary Node.
3)      Select Tables and right Click Select New Table.
4)      Name it “A_PurchaseOrder”.


Step 2: Now Create Form Node and Design your form like below.

1)      Expand AOT Node.
2)      Select Form Node and Right Click Select New Form and Name it “A_ChartForm”.
3)      Now Drag and Drop Table in Form DataSource.
4)      Select Design Node Right Click and Select New Controls and Add Grid Controls in Design Node.



How to Add ManagedHost Controls in your form.

Step 3: Right click Design->New control->ManagedHost
select Microsoft.Dynamics.AX.Framework.Client.Controls.ChartToolBar and change the name of the Control as ChartToolbarControlHost

Step 4: Right click Design->New control->ManagedHost
select System.Windows.Forms.DataVisualization.Charting.Chart and change the name of the control as GraphControl

Step 5: Now Open Declaration Method of form and Copy paste this code.


public class FormRun extends ObjectRun
{
    #define.waitTime(1000)
    Graphics    graphics;    
    Microsoft.Dynamics.AX.Framework.Client.Controls.ChartToolBar chartToolbarControl;
}

Step 6: Override init Method of form and Paste this code.


public void init()
{
    super();
    //ActiveX.Navigate("www.google.com");
    chartToolbarControl = chartToolbarControlHost.control();
    chartToolbarControl.set_ChartControl(graphControl.control());
    this.updateGraph();
    //Here you can set titles in graph
    //graphics.parmTitle("@SYS95906");
    //graphics.parmTitleXAxis("@SYS106478");
    //graphics.parmTitleYAxis("@SYS3065");
}

Step 7: create a new method called UpdateGraph () method and Paste this code.


void updateGraph()
{
    #MACROLIB.ChartFx
    COM series, serie;
    ;
    graphics = new Graphics();
    graphics.ManagedHostToControl(graphControl);
    //graphics.parmCreateType(#ct_cluster| #cT_tool);
    //graphics.parmActiveX(graphControl);
    //graphics.parmCreateType(#CT_LEGEND | #CT_3D);
    graphics.parmCreateType(#CT_LEGEND);
    //graphics.parmCreateType(#SERIES_COLUMN);
    graphics.create();
    graphics.parmTitle("Purchase Order Graph");
    graphics.parmTitleXAxis("Vender_Code");
    graphics.parmTitleYAxis("Purchase_Amount");
    graphControl.helpText("Purchase Order  graph");
    while select A_PurchaseOrder order by Vender_Code
    {
        if(A_PurchaseOrder.Status==PO_Status::Close)
        {
            while select A_PurchaseOrder
            order by Vender_Code where A_PurchaseOrder.Status==PO_Status::Close
            {
               graphics.loadData(A_PurchaseOrder.Vender_Code,A_PurchaseOrder.Purchase_ID,A_PurchaseOrder.Purchase_Amount);
            }
        }
    }
    graphics.showGraph();
}

Related Posts

Previous
Next Post »

Thanks for comments.....