Home Analytics DevShare
The community of Analytics developers are invited to follow and participate in the developer network.
OpenText technical experts collaborate with supported customers and partners in the Magellan product area.

Custom chart colors based on data set values

bhanleybhanley Senior Member
edited June 26, 2013 in DevShare
This report features two pie charts. The first uses the standard colors to render the pie chart. The second chart (on the right) leverages two scripts to check the category value and set the color to a specific RGB value. Specifically we are going to override the "beforeDrawDataPoint" and the "beforeDrawLegendItem" functions (code below).<br />
<br />
The colors applied are intentionally simple, primary colors that contrast to show the differences from the standard palette. There are four conditions in the sample data set and these conditions (Critical, High, Medium and Low) are used to determine the correct color for that marker.<br />
<br />
Code:
Chart Replacement Code (repeat if clause for each screened condition):
var Condition = dph.getBaseDisplayValue();
if(Condition.contains("Critical")) { fill.set(255, 0, 0);} // Set to RED
else if(Condition.contains("High")){ fill.set(255, 255, 0); } // Set to Yellow
...


Legend Replacement Code (repeat if clause for each screened value):

var Condition = lerh.getLabel().getCaption().getValue();
if(Condition.contains("Critical")) { lerh.getFill().set(255, 0, 0);} // Set to Red
else if(Condition.contains("High")){ lerh.getFill().set(255, 255, 0);} // Set to Yellow
...
<br />
The report design and data required to see the report in action are attached. The only modification you may need to run the report is to update the path assigned to the Flat File Data Source.<br />
<br />
Good Luck!
Sign In or Register to comment.