Change the legend order

Fuigi
edited February 11, 2022 in Analytics #1
<p>Hi I create a bar chart</p>
<p> </p>
<p>

Comments

  • Fuigi
    edited June 3, 2015 #2
    <p>here I attach a report exemple what I have.</p>
  • <p>You can modify the legendIndex of the series options to change the order of the items in the legend of an HTML5 chart.</p>
    <p>For Example:</p>
    <pre class="_prettyXprint _lang-js">
    beforeDrawSeries: function(series, seriesOptions, chart, seriesIndex)
    {
    if(seriesIndex == 0){
    seriesOptions.legendIndex = 2;
    }
    },
    </pre>
    <p>Take a look at the attached modified version of your sample report with this code in place.</p>
    Warning No formatter is installed for the format ipb
  • <p>Hum. When you're executing your report with that code the legend order is 2012 above 2011 ?</p>
    <p> </p>
    <p> </p>
    <p>because me I have that</p>
    <p> </p>
    <p>
  • <p>I'm not sure but I think I understand something.</p>
    <p> </p>
    <p>In this code we use serie, so serie 1 and serie 2 for exemple.</p>
    <p> </p>
    <p>"seriesIndex == 0" is for the serie 1 so ?</p>
    <p> </p>
    <p>But here I don't use a serie so I don't know if this has an influence. I use the "optional grouping" the seriesIndex can be used in this ?</p>
    <p> </p>
    <p>I try different way but nothing work</p>
  • <p>Yes, in the modified sample report I attached in my previous the legend displays the 2012 series above the 2011 series.</p>
    <p> </p>
    <p>When you use option grouping on the y series, it will create a separate series for each grouping dynamically when the chart is rendered. Therefore, when the chart is rendering there will be a separate series and series index created for each grouping.</p>
    <p> </p>
    <p>The legend index, like the series index, is the index associated with each item in the legend. Since your sample has 2 series, by default, the legend index for series 1 will be 0 and the legend index for series 2 will be 1.</p>
    <p> </p>
    <p>What I have done is to simply change the legend index of the first series to 2 which will place it after the second series in the legend index list causing it to display below the second series' legend entry.</p>
    Warning No formatter is installed for the format ipb
  • <p>Ok I understand :).<br><br>
    But why that don't work with me ? I try to generate your report without modification by me. And that make the screen you can see just above.</p>
    <p> </p>
    <p>I will try something else tomorow</p>
  • <p>Hmm that is strange as I just downloaded the report I attached myself and ran it without modifications and I get the correct result.</p>
    <p>See the attached screenshot for reference.</p>
    <p> </p>
    <p>What version of the designer are you using?</p>
    Warning No formatter is installed for the format ipb
  • <p>I use the last version 4.4 birt designer pro. <br>
     </p>
    <p>That don't work with my professionnal computer (and IE 10)</p>
    <p>
    I try with my personnal computer, with same version of Birt designer pro but google chrome and that work. </p>
    <p> </p>
    <p>I don't know if this issu is due to IE or my professionnal computer.</p>
  • <p>I do not believe it is specific to IE 10 itself.</p>
    <p>I just tested with IE 10 on my machine and it worked without issue. See the attached screenshot for reference.</p>
    <p> </p>
    <p>This makes me believe it is something specific to the machine.</p>
    <p>What are your browser security settings like on the machine with the issue?</p>
    <p>Do you get any javascript errors on the page?</p>
    <p> </p>
    <p>My guess would be that something is blocking this client side code from running.</p>
    Warning No formatter is installed for the format ipb
  • <p>That's work now. My network administrator make some modification and that work. :)</p>
  • <p>Wonderful.</p>
    <p>I am glad to hear you got it working.</p>
    Warning No formatter is installed for the format ipb
  • <p>Thank for your help !</p>
  • <p>You're welcome.</p>
    <p>I'm happy to help.</p>
    Warning No formatter is installed for the format ipb
  • <p>Really appreciate your answer and example. Thanks!</p>
  • Im new here, if threads are this old, are the attached report examples deleted or are they hidden in a way I cant easily see them

  • Thank you @Grimmr74

    It looks like this conversation was migrated from a previous system, and unfortunately the attachment was not included in the process. We do not have the original attachment available, nor the attachment in @JEFreeman 's comment. Our apologies for this inconvenience.

  • newcomer1
    edited February 21, 2023 #18

    Hi, my BIRT designer version is 4.9.0, and the parameters in beforeDrawSeries have changed. How to control legend order in this function now. Could anyone please help me with this problem?

    /**
     * Called before rendering Series.
     * 
     * @param series
     *      Series
     * @param isr
     *      ISeriesRenderer
     * @param icsc
     *      IChartScriptContext
     */
    
    function beforeDrawSeries( series, isr, icsc )
    {
    }
    


  • newcomer1
    edited February 21, 2023 #19

    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);
    }
    
    }