formatting attributes dynamically

acrubbo
edited February 11, 2022 in Analytics #1

I need help.

I want change all atributes in beforeFactory or initialize

I have

#FF0000

Custom
(#0.00)

right
col01

I can change color,textAlign,resultSetColumn

elemento="Data04"
myLabelHandle = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement(elemento);

myLabelHandle.setStringProperty("resultSetColumn", "col02");
myLabelHandle.setStringProperty("color", "Red");
myLabelHandle.setStringProperty("textAlign", "left");

How can I change numberFormat/pattern ?

Antônio Carlos

Best Answer

  • jfranken
    #2 Answer ✓

    In the onCreate event of a label:
    this.text = Formatter.format(parseFloat(this.text), "$##,####.##");

    When formatting an element that has the Format Number property, set the format dynamically using:
    this.getStyle().numberFormat = "$##,####.##"

    Warning No formatter is installed for the format ipb

Answers

  • jfranken
    #3 Answer ✓

    In the onCreate event of a label:
    this.text = Formatter.format(parseFloat(this.text), "$##,####.##");

    When formatting an element that has the Format Number property, set the format dynamically using:
    this.getStyle().numberFormat = "$##,####.##"

    Warning No formatter is installed for the format ipb
  • I need help.
    I want change all atributes in beforeFactory or initialize
    I have

      <data name="Data04" id="1269">
                            <property name="color">#FF0000</property>
                            <structure name="numberFormat">
                               <property name="category">Custom</property>
                                <property name="pattern">(#0.00)</property>
                            </structure>
                            <property name="textAlign">right</property>
                            <property name="resultSetColumn">col01</property>
                        </data>
    

    I can change color,textAlign,resultSetColumn
    elemento="Data04"
    myLabelHandle = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement(elemento);
    myLabelHandle.setStringProperty("resultSetColumn", "col02");
    myLabelHandle.setStringProperty("color", "Red");
    myLabelHandle.setStringProperty("textAlign", "left");
    How can I change numberFormat/pattern ?
    Antônio Carlos

  • jfranken ,
    thanks.

    my request was to put parentheses and red color when the number is negative, what I did was

    I create a new style ("style_parentheses") with the format="(#,###.##)"
    and in beforeFactory I did

    myLabelHandle = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("Data04");
    hr = StructureFactory.createHighlightRule();

    hr.setTestExpression("row['col01']";);

    hr.setValue1(0);

    hr.setProperty("operator","lt");
    hr.setProperty("color","Red");
    hr.setProperty("style","style_parentheses");

    ph = myHandle.getPropertyHandle("highlightRules");
    ph.addItem(hr);

    Antonio Carlos

  • Did you try selecting the element, then properties, then format number and choose (1,234.56) that would solve the parenthesis. Then choose the highlights tab and add a condition to make it red if it less than zero?