Label of legend entries

Options
Ingo
edited February 11, 2022 in Analytics #1
Hi,

I got some problems settings the labels in legend for a multi-line-chart.

I got multiple y-series with additional title information applied. When I use no grouping everything works fine and these titles are displayed...but when I add some additional grouping, only the grouping value is displayed. Is it possible to add the series title the legend entries. I tried to modify the values via script but I don't have information about the current series there...So, is there any chance to do this? I could imagine the following output in the legend.
X <series-identifier1> - <groupvalue1>


Or is it possible to add 2 legends. One for the symbols or different line styles to explain/identify the different y-series and one for the coloring to explain the groupings?

Thanks,

Ingo

Comments

  • JasonW
    edited December 31, 1969 #2
    Options
    Ingo,

    Color by categories. This should do what you want. See attached report.

    Jason
  • Ingo
    edited December 31, 1969 #3
    Options
    Hi,

    thanks for the quick answer, but unfortunately this doesn't solve my problem. In your example you have only one column for the values. In my case I got multiple which leads to multiple series...

    For example, I got values from different places for specific items

    Item; Time; value1; value2
    A;500ms; null; 8
    A; 700ms; 5;null
    B; 750ms; 20; null
    ...

    X-Axis -> Time
    Grouping on Item
    2 Series: 1. value1, 2. value2


    Now, the legend should display:
    <Symbol for series1> <Label for series 1 > <Item>
    <Symbol for series2> <Label for series 2 > <Item>


    Thanks,

    Ingo
  • JasonW
    edited December 31, 1969 #4
    Options
    Ingo,

    I am not certain this can be done.
    You could have the legend show up like

    symbol for item a label for a
    symbol for item b label for b
    _________Separator
    symbol for item a label for a
    symbol for item b label for b

    Where the separator shows up once and above is series one and below is series two.

    Jason
  • Ingo
    edited December 31, 1969 #5
    Options
    Hi,

    thats exactly what I got right now...but because if up to 6 series its hard to "remember" what one series represents...Is it possible to change the appearance of the separator so I could display a text for the series? ;-)

    or is it possible to add another legend for the series?

    Thanks,
    Ingo
  • JasonW
    edited December 31, 1969 #6
    Options
    Ingo,

    This is a tough one. I suggest you log a bugzilla entry for this. You may also be able to add some script like

    var series_number = 0;
    function beforeDrawLegendItem(lerh, bounds, icsc)
    {

    if( lerh.getDataIndex() == 0 ){
    series_number +=1 ;
    }
    var old_label =lerh.getLabel().getCaption().getValue();
    lerh.getLabel().getCaption().setValue(old_label + " -- Ser" + series_number);
    }

    Jason
  • Ingo
    edited December 31, 1969 #7
    Options
    Hi Jason,

    nice idea. ;-)

    I will try that...can I access the title of the corresponding series from there? Or do I need another "lookup-array" for this issue? How could that be automated?

    Thanks,
    Ingo
  • JasonW
    edited December 31, 1969 #8
    Options
    Ingo,

    Try something like:
    importPackage(Packages.java.util);
    importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
    importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
    importPackage(Packages.org.eclipse.birt.chart.model.type.impl);
    var cm = icsc.getChartInstance();

    var xAxis = cm.getAxes().get(0);
    var yAxis = xAxis.getAssociatedAxes().get(0);

    var yser1 = yAxis.getSeriesDefinitions().get(0).getDesignTimeSeries().getSeriesIdentifier();
    var yser2 = yAxis.getSeriesDefinitions().get(1).getDesignTimeSeries().getSeriesIdentifier();
    if( lerh.getDataIndex() == 0 ){
    series_number +=1 ;
    }
    var old_label =lerh.getLabel().getCaption().getValue();
    if( series_number == 1 ){
    lerh.getLabel().getCaption().setValue(old_label + yser1);
    }else{
    lerh.getLabel().getCaption().setValue(old_label + yser2);
    }
    }
  • Ingo
    edited December 31, 1969 #9
    Options
    Okay,

    thanks. I'll try that as a workaround.

    Ingo
  • Ingo
    edited December 31, 1969 #10
    Options
    Hi,

    since I haven't done scripting till now. Do I any more prerequisites to run this script? Do I need to copy more libraries or something like that to the tomcat?

    As soon as I run the following method in the script I get a null-pointer-exception.

    importPackage(Packages.java.util);
    importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
    importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
    importPackage(Packages.org.eclipse.birt.chart.model.type.impl);

    function beforeDrawLegendItem(lerh, bounds, icsc)
    {

    var cm = icsc.getChartInstance();
    }


    -->
    null ( 1 time(s) )
    detail : org.eclipse.birt.chart.exception.ChartException
    at org.eclipse.birt.chart.reportitem.ChartReportItemPresentationImpl.onRowSets(ChartReportItemPresentationImpl.java:607)
    at org.eclipse.birt.report.engine.presentation.LocalizedContentVisitor.processExtendedContent(LocalizedContentVisitor.java:772)
    at org.eclipse.birt.report.engine.presentation.LocalizedContentVisitor.visitForeign(LocalizedContentVisitor.java:414)
    at org.eclipse.birt.report.engine.content.impl.ForeignContent.accept(ForeignContent.java:59)
    ...
    Caused by: java.lang.NullPointerException
    at org.eclipse.birt.chart.script.ScriptHandler.convertException(ScriptHandler.java:1128)
    at org.eclipse.birt.chart.script.ScriptHandler.register(ScriptHandler.java:1085)
    at org.eclipse.birt.chart.reportitem.ChartReportItemPresentationImpl.onRowSets(ChartReportItemPresentationImpl.java:465)
    ... 99 more


    Thanks,
    Ingo
  • Ingo
    edited December 31, 1969 #11
    Options
    Okay,

    it runs now. I don't know why but I created the same chart again and now it works, in generally. The problem I got now is, that in another chart, I got multiple y-Axis. I tried the following but unfortunately got always the same label...

    mportPackage(Packages.java.util);
    importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
    importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
    importPackage(Packages.org.eclipse.birt.chart.model.type.impl);

    var cm = icsc.getChartInstance();
    var xAxis = cm.getAxes().get(0);
    var yAxis = xAxis.getAssociatedAxes().get(0);
    var yAxis1 = xAxis.getAssociatedAxes().get(1);
    var yAxis2 = xAxis.getAssociatedAxes().get(2);

    var yser1 = yAxis.getSeriesDefinitions().get(0).getDesignTimeSeries().getSeriesIdentifier();
    var yser2 = yAxis1.getSeriesDefinitions().get(0).getDesignTimeSeries().getSeriesIdentifier();
    var yser3 = yAxis2.getSeriesDefinitions().get(0).getDesignTimeSeries().getSeriesIdentifier();

    if( lerh.getDataIndex() == 0 ){
    series_number +=1 ;
    }
    var old_label =lerh.getLabel().getCaption().getValue();

    switch ( series_number ) {
    case 1: lerh.getLabel().getCaption().setValue(yser1 + " - " + old_label); break;
    case 2: lerh.getLabel().getCaption().setValue(yser2 + " - " + old_label); break;
    case 3: lerh.getLabel().getCaption().setValue(yser3 + " - " + old_label); break;
    default:
    }
    }

    Any suggestion? Thanks.

    Ingo
  • JasonW
    edited December 31, 1969 #12
    Options
    What line of the script got the same label?

    Jason
  • Ingo
    edited December 31, 1969 #13
    Options
    Okay got it.

    It was just a typo.

    Thanks for your help. ;-)

    /Ingo