[HOWTO] Using PeopleCode to Create Charts

[HOWTO] Using PeopleCode to Create Charts

Stumbled across this post about how to create charts in PeopleCode with a nice, clean approach.  From The PeopleSoft Blog:

For those who haven’t tried creating a chart using peoplecode. I do not have the code which I did while I was working with my first company. But this example below from peoplebooks will give you an idea. You can create great charts using pagelet wizard also , but when the performance part is considered, I will recommend the usage of chart class.

The below chart is created from a record with three fields, relating to sales, month, and product. The series in the chart are based on the product. The following is the complete code sample.

Global Chart &oChart;

&oChart = GetChart(QE_CHART_DUMREC.QE_CHART_FIELD);

&oChart.SetData(Record.QE_CHART_RECORD);
&oChart.SetDataYAxis(QE_CHART_RECORD.QE_CHART_SALES);
&oChart.SetDataXAxis(QE_CHART_RECORD.QE_CHART_PRODUCT);

&oChart.SetDataSeries(QE_CHART_RECORD.QE_CHART_REGION);

&oChart.Type = %ChartType_2DStackedBar;

&oChart.HasLegend = True;
&oChart.LegendPosition = %ChartLegend_Right;

&oChart.XAxisLabelOrient = %ChartText_Vertical

Image67

To create a chart:

  1. Open PeopleSoft Application Designer.
  2. Open the page where the chart is to be inserted.
  3. Insert the chart control by either:
    • Clicking on the chart icon in the toolbar, or
    • Selecting Insert, Chart
  4. Draw the chart control on the page.
  5. Associate the chart control with a record field

Every chart control must be associated with a record field. This is just the field for the chart control. It is not the field used for drilling down for data in the chart.

Bring up the chart control properties by either

    • Double-clicking on the chart control, or
    • Right-clicking on the chart control and selecting Page Field Properties.
  1. Select the record name and field for the chart.

On the Record tab of the chart control properties, select the record and field for the chart.

To make the control a page anchor, select the Enable as Page Anchor on the General tab.

  1. Write your PeopleCode.

In some event on the page, such as Activate, put the PeopleCode you need for populating the chart.

  1. Get the chart.

The first thing you must do is get the chart. You must use the record and field name that you associated with the chart control on the page.

&oChart = GetChart(QE_CHART_DUMREC.QE_CHART_FIELD);

  1. Set the data records.

Set the data record. The SetData function associates the record data with the chart. Then use the SetDataYAxis and SetDataXAxis functions to associate specific fields in the record with the Y axis data and the X axis data.

&oChart.SetData(Record.QE_CHART_RECORD);

&oChart.SetDataYAxis(QE_CHART_RECORD.QE_CHART_SALES);

&oChart.SetDataXAxis(QE_CHART_RECORD.QE_CHART_PRODUCT);

This is all the code needed to create a chart. You don’t need to set the chart type: the default is a 2D bar chart. You don’t need to set the series unless you want to group your data. Everything else is also optional.

  1. (Optional) Set the data series.

In this example, we want to set the region as the series. This means that the data will be grouped according to the region.

&oChart.SetDataSeries(QE_CHART_RECORD.QE_CHART_REGION);

  1. (Optional) Set the chart type.

Because we want a stacked bar for the chart, we must set the Type property of the chart. This means that each product (footballs, rackets, and so on) will have a single bar, and the data series (California, Oregon, and so on) will be what is ‘stacked’.

&oChart.Type = %ChartType_2DStackedBar;

  1. (Optional) Set legend and label attributes.

For this example, we want a legend, and want it to appear in the right side. In addition, because the text of the series labels is so large, they must be vertical to display all of them.

&oChart.HasLegend = True; &oChart.LegendPosition = %ChartLegend_Right;

&oChart.XAxisLabelOrient = %ChartText_Vertical;

###

More links:

MIPRO Consulting main website.

You should follow MIPRO on Twitter and Facebook.

About this blog.


+ posts

Leave Comment