Search This Blog

Monday, 13 October 2014

Displaying Graphs and Charts in Ax 2012 Form

Hi,

I would like to share you how to display data in graphs and charts in AX 2012 Forms

for an example i have displayed the customer details whose invoice amount is greater than 10000 and less than 20000

step 1:

create a new form called CustomerInvoiceAmountGraph

step 2:

add custInvoicaJour table as datasource

step 3 : 

override init() method and class declaration method

public class FormRun extends ObjectRun
{
      Graphics    graphics;
      CustInvoiceJour custinvoiceJourGraphValues;
      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.showchart();
}

step 4:

create a new method called showchart() where your logic is placed to display the customer data
whose invoice amount is greater than 10000 and less than 20000

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.create();
    graphics.parmTitle("@SYS95906");
    graphics.parmTitleXAxis("CustAccount");
    graphics.parmTitleYAxis("Amount");

// populate the chart with data

while select CustInvoiceJour where  CustInvoiceJour.InvoiceAmount>=10000  && CustInvoiceJour.InvoiceAmount <=20000
    {
        graphics.loadData( CustInvoiceJour.InvoiceAccount,  ' ' , CustInvoiceJour.InvoiceAmount);
    }

    graphics.showGraph();

}

step 5:

Right click Design->New control->ManagedHost

select Microsoft.Dynamics.AX.Framework.Client.Controls.ChartToolBar


step 6:

Right click Design->New control->ManagedHost

select System.Windows.Forms.DataVisualization.Charting.Chart and change the name of the control as GraphControl

output:

Happy Daxing.....

7 comments:

  1. how can we pass the values of fields of one form into fields on other form, can u suggest me where to write the code or what are the methods to use

    ReplyDelete
  2. http://axguruu.blogspot.in/2014/06/passing-arguments-from-one-form-to.html?m=1
    Refer this link

    ReplyDelete
  3. Is there a way to change the color of the bars?

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Yes you can change the color of the bars.

    ReplyDelete
  6. is there's a way to change the scaling if the we change the chart type into stacked one?

    ReplyDelete
  7. Hi..
    Can anyone help me out with changing the orientation of the labels on either of the axes through code?

    ReplyDelete