Stacked Bar Series - How to reorder the legend

Options
noe-su
edited February 11, 2022 in Analytics #1
<p>I have a stacked bar chart with five series (A, B, C, D, E).</p>
<p>The chart is drawn as I like to have it: A is at the bottom and E is stacked at the top.<br>
But in the Legend A is at the top and E is listed as last.</p>
<p>How can I change the legend order without changing the stack order?</p>

Comments

  • <p>Hi,</p>
    <p> </p>
    <p>Which version of BIRT are you running? What type of chart output? SVG? HTML5?</p>
    <p> </p>
    <p>I have tried both BIRT Open Source and BIRT Commercial and got correct results as show in this screen shot:</p>
    <p> </p>
    <p>
    Warning No formatter is installed for the format ipb
  • <p>It is Birt Version 4.4.2.v201410272105 (cannot take another one cause it is integrated into our software).<br>
    The output format is ODP.</p>
    <p>I'll send you the design. It has two charts in. It is about the second one with the name "theChart".</p>
  • <p>Attached the report design and a picture of the output.</p>
    <p>The chart has 5 stacked bar series and 10 not stacked line series.</p>
  • <p>Hi,</p>
    <p> </p>
    <p>Interesting... It appears the legend is displayed in reverse order only when the stacked chart also includes series displayed as lines.</p>
    <p> </p>
    <p>Anyhow, with some chart scripting, I was able to reverse the order. I found the script from an old post on eclipse.org, and applied it "as is".</p>
    <p> </p>
    <p>Since I cannot run your report, I am sending you a sample report built with Classic Models. You can copy and paste the chart scripting from my example to your report; it should work.</p>
    <p> </p>
    <p>Hope this helps,</p>
    <p> </p>
    <p>P.</p>
    Warning No formatter is installed for the format ipb
  • <p>Thanks a lot. It did work.</p>
  • Hi, my BIRT version is 4.9.0. And I have the same problem. The legend order is reversed when stacking the bar. Could anyone please help me with it? I want to reverse the legend order or control it.

  • I solve the problem by swapping the left and right item locations, the order will be reversed. It works fine for me.

    function beforeRendering( gcs, icsc )

    {

    var legendItems = gcs.getRunTimeContext().getLegendLayoutHints().getLegendItemHints( );


    for( i=0; i < legendItems.length / 2; i++ ){

    // left item and right item

    var leftItem = legendItems[i];

    var rightItem = legendItems[legendItems.length-1-i];

    //swap their location(top, left)

    top = leftItem.getTop();

    left = leftItem.getLeft();

    leftItem.top(rightItem.getTop());

    leftItem.left(rightItem.getLeft());

    rightItem.top(top);

    rightItem.left(left);

    }


    }