This example sets the number type to currency for a Sales measure in a graph. You can
accomplish this task in a similar way for a table or crosstab, by setting the rule bundle on a
GridViewRuleFormatter
instead of a GraphRuleFormatter
.
This example uses the following:
For the discriminator, the QDRDiscriminator
For the mergeable object, the ViewFormat
The following code creates the DiscriminatorRule
, the RuleBundle
, and the Vector
for rule bundles. Then it sets the vector of bundles in the GraphRuleFormatter
, which implements the GraphFormatManager
interface.
//create a ViewFormat ViewFormat vf_currency = new ViewFormat(); //Set the number type to currency vf_currency.setNumberType(NUMTYPE_CURRENCY); //Create a discriminator that specifies when the number is currency //First, create a QDR that specifies Sales as the measure QDR qdr_Sales = new QDR("XP_MEASUREDIM", "XP_MEASUREDIM", "SALES"); //Then, create the QDRDiscriminator //This discriminator specifies that, in the formatted item, the //measure must be "SALES". QDRDiscriminator dsc_Sales = new QDRDiscriminator(qdr_Sales, SUPERSET); //Create a DiscriminatorRule DiscriminatorRule dr_currSales = new DiscriminatorRule(); //Set the discriminator, to tell when the rule should apply dr_currSales.setDiscriminator(dsc_Sales); //Set the ViewFormat (mergeable object), to tell what formatting should be //applied dr_currSales.setFixedMergeable(vf_currency); //Put the rule in a rule bundle RuleBundle rb_measureFmt = new RuleBundle(); //Add the discriminator rulerb_measureFmt.addRule(dr_currSales); //Create a vector for the bundle, and add the bundle Vector rbVector = new Vector(); rbVector.addElement(rb_measureFmt); //Get the rules style manager for the graph //assumes that the graph you want is "myGraph" GraphRuleFormatter gfm = (GraphRuleFormatter)myGraph.getGraphFormatManager(); //Add our rule bundle vector to whatever the manager has rbMgrBundle = gfm.getBundles(); if (rbMgrBundle == null){ gfm.setBundles(rbVector); } else{ rbMgrBundle.addElement(rb_measureFmt); //you must set this so the manager knows to refresh gfm.setBundles(rbMgrBundle); }