BIRT: setting the max Value of the scale in the y-axis dynamic

Hello everyone,
I'm working on a report where i have a Bar-chart. I'm trying to find a way to tell the y-axis to set it's max-scale value as the max value that it comes from the Data when placed on the Chart.

Please see the following picture for better understanding

I'm thinking of some like: calling the y-Data using : getOrthogonalValue() and determine the max value of it and then set this value as the max scale for the y-axis but i don't know how to implement it . So I would be thankful for your suggestions and help

Thanks in advance

Khaled

Comments

  • I hope to get help with the problem explained above since it blocks me from continuing my project.

    Would be thankful

  • edited November 12

    What chart type are you using? You'll likely need to write some script to look at the data to find the max and change the scale to the max. How you do that will depend on the type of chart.

    For example, if you're using HTML5 charts, you can use highcharts APIs to do this. I think that would be the easiest one to implement.

    Chad Montgomery
    Customer Support Engineer
    OpenText
  • Hello Chad,
    First thank you so much for your answer. I'm surprised and glad to some reaction on this forum as i rarely get help (except from Jfranken):')
    yes you're absolutely right, this must be done through script but my programming experience is not so far

    I'm using Bar-chart with SVG-format.
    The exportation of the report is: pdf.

    here is what i tried to do:

    As you see I'm trying to catch the max value of the y-axis and save it some how under (MaxValue) as global parameter and then call it in the beforeGeneration() method

    I believe this can be done but I don't know how to get the maxValue of the y-axis (after saving it as global) and then call it in another generation phase

    hope i could answer your question
    Thanks in advance

  • I believe beforeDrawDataPoint occurs after beforeGeneration, which would explain why it's not working for you. You do have the right idea though. I'll take a look to see what I can find.

    Chad Montgomery
    Customer Support Engineer
    OpenText
  • I would be thankful for that :smile:

  • edited November 14

    Let me preface by saying that's likely a million different ways you can do this, but I decided to go about it in the afterDataSetFilled event.

    function afterDataSetFilled( series, dataSet, icsc )
    {
        importPackage(Packages.java.util);
    
        if(series.getDisplayName() == "Bar Series"){
            var max = Collections.max(Arrays.asList(dataSet.getValues()));
    
            xAxis = icsc.getChartInstance().getBaseAxes()[0];
            yAxis = icsc.getChartInstance().getOrthogonalAxes(xAxis, true)[0];
    
            yAxis.getScale().getMax().setValue(max);
        }
    }
    

    The main thing to look out for, is to ensure that this code only runs once, for the apropriate series.

    Chad Montgomery
    Customer Support Engineer
    OpenText
  • edited November 14

    Hello Chad,
    thank you very much for your help. I actually tried your solution. It returns with the following Error:

    **
    Chart ExampleChart:

    • TypeError: Cannot call method "setValue" of null at line 220 of chart script:''**
      So the variable Max has a null value which i don't know why.

    Have you got an idea?

    Thanks in advance

  • Try stepping backwards and make sure that dataSet.getValues() returns a value. If it doesn't, check to make sure you're running it within the right series.

    Chad Montgomery
    Customer Support Engineer
    OpenText
  • your're right i had the name of the Series wrong. I actually corrected it and the Error disappear but obviously it displays no change as the scale should be 36 instead of 28

    please note, that on the y-axis the I've set a Datarow that has a value of (1 )for all data on the x-axis. On the x-axis the data are grouped with the function sum. So the chart looks at how many values are located in every interval on the x-axis and then count there ones and display the sum on the y-axis

  • I hope you‘re still here as your suggested code doesn‘t make any change. Especially wenn you said that there is a thousend way to do this :smile:

    Thanks in advance
  • Could you share your report?

    Chad Montgomery
    Customer Support Engineer
    OpenText
  • edited November 18

    of course. your code is implemented in the last histogram

    Thanks in Advance

  • Try setting your scale to some static value. It will be overwritten by the code, but I find it's more difficult to get it to work when it starts off at auto.
    Format Chart > Y-Axis > Scale > Uncheck Auto for Max value and set an example value.

    Hopefully that will do it for you.

    Chad Montgomery
    Customer Support Engineer
    OpenText
  • Auto can only be unchecked when checking the step instead which i dont want because the step is set dynamically in the script

    However i tried it but it still has no effect as you see

    I believe this is not easy as i expected

    thanks in advance

  • I believe you had the series name right the first time, that is "Bar Series". The reason changing it removed the error for you was because the if statement never came back true when it was comparing with "FAILED", meaning the code causing the error never ran.

    In any case, if you switch back to "Bar Series", I think you'll be good to go.

    Chad Montgomery
    Customer Support Engineer
    OpenText
  • According to your code, the if statement will be executed if the series name matches the name given in the if statement. As displayed below the series name in my case is FAILED.

    However, when i set the series Name in the if statement to "Bar Series " it returns the following error :

    I found a workaround by defining a column in the dataset that counts how many values i have in total and then set it a global parameter and in the end i called it in the beforeGeneration() method ans set it as max value of the Yaxis.

    I thank you so much for your help as you inspired me to the solution. There is just one remaining problem where i've been stuck for ages.

    In the report below you can see that the Data on the X-axis are grouped but some bars exceed there Interval to wich they belong to. the step size is being retrieved from above (see top of the report).

    So is there a way to dynamically shift the bars so that they are located in exactly in there interval (Ideal case they fit there Interval and most importanlly do not exceed it as this will confuses the reader so he doesn't know which bar belongs to which Interval)

    I've been working on this for 4 months but no hope. I really need to get this work for my Project in the company.

    Would be so thankful if you could help

    Thanks in Advance.

    Khaled

  • If you attached an image for your question about intervals, I think it got lost. Since it's a new question, I'd suggest starting a new thread and we can see if we have any suggestions.

    Chad Montgomery
    Customer Support Engineer
    OpenText
  • Jeff F.
    Customer Support Engineer I
    OpenText
  • Jfranken, thank you my friend :smile:

Sign In or Register to comment.