Freigeben über


Charts in Microsoft Dynamics AX 2012

 

 

 

 

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, then call Update to diplay 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

 

Set both to have a Width of Column Width

 

// Class Declaration

public class FormRun extends ObjectRun

{

      Graphics graphics;

    Microsoft.Dynamics.AX.Framework.Client.Controls.ChartToolBar chartToolbarControl;

}

public

void init(){

        super();

// create an runtime reference to the toolbar control 

   chartToolbarControl = chartToolbarControlHost.control();

 

// bind the tool bar to the chart control by passing an instance of the chart control to it

    chartToolbarControl.set_ChartControl(graphControl.control());

      this.createSampleData();

    this.showchart();

}

void showchart()

{

// create an instance of the X++ to .NET abstraction class and bind it to the chart control

    graphics =  new Graphics();

    graphics.ManagedHostToControl(graphControl);

 

// set your abstracted chart options

    graphics.parmCreateType(#CT_LEGEND | #CT_3D);

    graphics.create();

    graphics.parmTitle("@SYS95906");

    graphics.parmTitleXAxis("@SYS106478");

    graphics.parmTitleYAxis("@SYS3065");

 

// populate the chart with data

   whileselect tmpAccountSum 

       orderby TransDate

    {

        graphics.loadData( date2str(tmpAccountSum.TransDate,-1,-1,-1,-1,-1,-1, DateFlags::None),  tmpAccountSum.Txt, tmpAccountSum.Qty01);

    }

    graphics.showGraph();

}

 

 // create some sample data

void createsampledata()

{   

    tmpAccountSum.TransDate = 01\01\2007;

    tmpAccountSum.Qty01 = 1;

    tmpAccountSum.Txt = 'Group1';

    tmpAccountSum.insert();

 

    tmpAccountSum.TransDate = 02\02\2007;

    tmpAccountSum.Qty01 = 2;

    tmpAccountSum.Txt = 'Group1';

    tmpAccountSum.insert();

 

    tmpAccountSum.TransDate = 02\02\2007;

    tmpAccountSum.Qty01 = 1;

    tmpAccountSum.Txt = 'Group2';

    tmpAccountSum.insert();

 

    tmpAccountSum.TransDate = 03\03\2007;

    tmpAccountSum.Qty01 = 3;

    tmpAccountSum.Txt = 'Group2';

    tmpAccountSum.insert();

 

    tmpAccountSum.TransDate = 04\04\2007;

    tmpAccountSum.Qty01 = 1;

    tmpAccountSum.Txt = 'Group1';

    tmpAccountSum.insert();

 

    tmpAccountSum.TransDate = 04\04\2007;

    tmpAccountSum.Qty01 = 2;

    tmpAccountSum.Txt = 'Group3';

    tmpAccountSum.insert();

 

    tmpAccountSum.TransDate = 05\05\2007;

    tmpAccountSum.Qty01 = 3;

    tmpAccountSum.Txt = 'Group3';

    tmpAccountSum.insert();

 

    tmpAccountSum.TransDate = 05\05\2007;

    tmpAccountSum.Qty01 = 2;

    tmpAccountSum.Txt = 'Group2';

    tmpAccountSum.insert();

}