BIRT- set the Bar-width of a Bar chart dynamically

Hello everyone,
I'm working on a report using BIRT. In my report I have a Bar chart and I'm trying to adjust it's Bar-width so that all Bars will have a width value that is retrieved from my dataset. I have managed to get the with-value named (steps) stored in a parameter but i don't know where i should use it. I've looked in the Internet and found the method setSeriesThickness() but no idea if it's what i should use.

Please see the following pic to understand i I'm trying to do.

Would appreciate your help

Thanks in advance
Khaled

Comments

  • edited August 12

    To change the bar width, go to the Format Chart tab in the chart editor. Select Chart Area on the top of the left pane. Click the General Properties button on the bottom middle of the right pane. Edit the Unit Spacing setting in the General Properties popup window. Decreasing the spacing increases the bar width.

    To set the value dynamically, use the following code:

    function beforeGeneration( chart, icsc )
    {
    chart.setUnitSpacing(20);
    }
    

    If you set the value to a small number (i.e. 5) and the bar is still not wide enough, you will need to alter the size of the chart or the axis properties to spread out the bars.

    Jeff F.
    Customer Support Engineer I
    OpenText
  • edited August 12

    Hi Jeff,
    thank you for your support.
    I have tried setting the Bar-width as you mentioned calling a parameter named step which was also used for setting the step-size dynamically on the x-axis, but it shows no effect when previewing the report. The unit spacing in the chart wizard accepts no decimal numbers but between 0-100(assumed i want a fix Bar-width which is 0.115696). So does my script have no effect because the params["step"] includes a decimal number which is not accepted or because i need to alter the size of the chart?. if yes can you please advice me how?

    Please see the following pic to understand what i mean.

    thanks in advance

  • Hi Jeff,
    I actually tried it once again after restarting my PC it turns out that the following script :
    chart.setUnitSpacing(icsc.getExternalContext().getScriptable().getParameterValue("step")); that i've added in the previous picture makes the bars-width wider but not as it should. Practically, it should fill the step size completely.
    Please see the following picture for better imagination.

    hope you can help me with this.
    many thanks
    Khaled

  • edited August 17

    Hi jeff,
    hope you can help me with this as well. In fact, The SetUnitSpacing() increases the width of the bars, but this is done independent from the axis-scaling.
    I mean, i want that each bar (where it exists) to fill it's Interval completely like the following

    Thanks in advance

  • edited August 19

    Hi Khaled,

    See if this helps:

    • Go to the Format Chart tab in the chart editor.
    • Select "X-Axis" on the left.
    • Click the "Gridlines" button.
    • Check the checkbox named "Cross between Categories" and close to save.
    • Next, click the "Label" button.
    • Change Insets to move the labels and close to save. It will take numerous attempts to line them up properly.
    Jeff F.
    Customer Support Engineer I
    OpenText
  • Hi Jeff,
    thank you for your Help. Actually, your idea works with me, when the data remain the same. This means, the data retrieved from the data source change at the runtime. This means, that your steps will apply correctly when the chart data values are changed. I will illustrate an example in order to understand what i'm trying to do.

    Therefor, i must do this using chart-script. I found something like beforeDrawSeries() and beforeDrawDatapoint. Here i think i can call the values of my x-axis ( where it exists) or the Series and force them to stay in my grouping-Interval.

    I hope i could express the problem and hope you could help me.

    thanks in advance.

  • Thanks for the detailed description. After I posted my previous response, I was wondering if there was a way to make it dynamic but I haven't had a chance to work on it in the interim. I will let you know what I find.

    Jeff F.
    Customer Support Engineer I
    OpenText
Sign In or Register to comment.