HOWTO: Create a chart with drill-downs

bsoremsugar —  June 21, 2011 — 4 Comments

Adding drill-downs to charts is a pretty simple task once you know which properties need to be set. If we look at the following snippet of chart code, we’ll see the 3 properties that should be set to get drill-downs working.

require_once('include/SugarCharts/SugarChartFactory.php');

$sugarChart = SugarChartFactory::getInstance();
$sugarChart->base_url = array(
     'module' => 'Opportunities',
     'action' => 'index',
     'query' => 'true',
     'searchFormTab' => 'advanced_search',
     );
$sugarChart->url_params = array( 'assigned_user_id' => $current_user->id );
$sugarChart->group_by = array('sales_stage',true);

 

The first two lines of code instantiate our chart engine class. Line 3 sets up our base URL, the static part of the URL that we want to construct. In this case, we would be getting a base url that looks like this:

index.php?module=Opportunities&action=index&query=true&searchFormTab=advanced_search

 

Line 8 sets any additional parameters that you might need to construct to get the proper URL. Here we are adding an assigned_user_id parameter to our url because this particular chart only returns data for the current user. Line 9, which is the group_by property, we set an array with 2 elements. The first element defines the database field that we are querying against and the second lets the charting engine know we want to enable drill-downs for this particular chart. The final url should look something like this:

index.php?module=Opportunities&action=index&query=true&searchFormTab=advanced_search&assigned_user_id[]=1&sales_stage=Qualification

 

When the user clicks on this segment of the chart, they will be taken to the Opportunities list view that is filtered by assigned_user_id and sales_stage.

4 responses to HOWTO: Create a chart with drill-downs

  1. 

    I don’t think this is a drill down but this is a drill through.

  2. 

    Ryuhei, no its a deeply drilled one.

    Sample
    Documents

  3. 

    In which file/function the above code contains?

  4. 

    Hey Lam, couldĀ  you tell us where your snippet of code is located? I’ve done a find in files and can’t find it anywhere. I’ve found two functions in the SugarChart.php that appear to have some relation to building a URL i.e. constructBaseURL and constructURL. Any assistance would be greatly appreciated…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s