Adjusting slices in JavaScript

JMaleski
edited February 11, 2022 in Analytics #1
I am trying to adjust the visible variable of a pie slice for a chart in the JavaScript section. How ever, I am having considerable difficulty finding the actual objects. My best attempt so far has been within the beforeGeneration() method where I can access the chart's setMinSlice method. Getting any more specific slice attributes has eluded me thus far.

I suppose my question boils down to are the slice values stored in an accessable Object via the JavaScript functions that would allow me to check it's area (or other attributes) in order to dynamicaly disable the visiable attribute?

Thanks for your time :)

Comments

  • Virgil Dodson
    Virgil Dodson E admin
    edited December 31, 1969 #2
    Hi JMaleski,

    You can get to the pie slice values with the getOrthogonalValue() method like the example below. I played around with setting visibility for a data point but this just removes the fill area and not the labels, lines, borders, and legend.

    function beforeDrawDataPoint(dph, fill, icsc)
    {
    value = dph.getOrthogonalValue();
    if (value < 40000) {
    fill.setTransparency(0);
    }

    This approach will also leave blank parts of the pie showing. You might try filters on the chart if you want pie slices removed and the rest of the pie filled in.
    Warning No formatter is installed for the format ipb
  • JMaleski
    edited December 31, 1969 #3
    Virgil,

    Thanks for the reply, it is much appreciated! :)

    I tried the approach you suggested and unfortunitely it doesn't seem like the beforeDrawDataPoint method is ever getting called. I made a simple log output using the following code:

    importPackage(Packages.java.util.logging);

    var fileHandler = new FileHandler("c:/temp/cbirt_log.log", true);
    var rootLogger = Logger.getLogger("");
    rootLogger.addHandler(fileHandler);

    function log ( str )
    {
    Logger.getAnonymousLogger().info(str);
    }

    Using that, I did a simple log inside the method mentioned earlier and haven't seen any output (nor any errors being displayed in the report).

    As a small caveat, I previously placed some JavaScript in the beforeDrawDataLabel to remove a label if it is smaller then a certain percent and it works perfectly. I also put the same log call into this method just as a sanity check to verify it is logging correctly (which it is).

    Any thoughts as to why this method would not be getting called? Thanks again!
  • Virgil Dodson
    Virgil Dodson E admin
    edited December 31, 1969 #4
    What version of BIRT are you using?

    If you are using BIRT 2.2 or higher, then take a look at my enclosed example. Does this one run the script?
    Warning No formatter is installed for the format ipb
  • JMaleski
    edited December 31, 1969 #5
    Virgil,

    Thanks again for taking a look at the issue. I am using ver 2.1.

    I ran your .rptdesign file in 2.2 and it all worked correctly. I then created the same report (duplicating the data source, data set, and pie chart) copying just the beforeDrawDataPoint method into version 2.1. Unfortunitely it also is not being executed.

    As a quick sanity check, I added a log print call to both versions inside the beforeDrawDataPoint method. In 2.1 there was no output, in the 2.2 there were 14 different log message tags.

    I'm pretty sure this might just be a version limitation, but if you have any other thoughts I'm open to suggestions :) Thanks again for your help, and have a good weekend!