Dynamic Chart Markers

edited December 31, 1969 in Designing Analytics Reports
Hi,

i want to generate a chart with markers on the x-axis and the x-axis is of type text.

i try it with this script:

function beforeGeneration(chart, icsc){
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);

var chart = icsc.getChartInstance();
var yAxis = chart.getAxes().get(0).getAssociatedAxes().get(0);

var EoD = icsc.getExternalContext().getScriptable().getParameterValue("EoD");


top_ml = MarkerLineImpl.create(yAxis, NumberDataElementImpl.create(EoD));
top_ml.getLabel().getCaption().setValue("EoD " + EoD);
top_ml.getLineAttributes().getColor().set(0,200,0);
top_ml.getLineAttributes().setStyle(LineStyle.SOLID_LITERAL);
top_ml.getLineAttributes().setThickness(2);

}

But how can i change the axis? and does this also work for text axis?

thx

Comments

  • mwilliamsmwilliams BIRT Guru
    edited December 31, 1969
    Can you explain a little more about what you're trying to do? What are the axis values? What is the value of the parameter? One of the axis values? I'm not sure if it can be done, but if you answer the questions above, or just recreate the issue with the sample database, I'll take a look. :)

    Regards,

    Michael Williams

    eSignLive Evangelism & Community Manager | eSignLive by VASCO
     
    Find me on:
    Twitter
    Facebook
    Blog

    LinkedIn

    eSignLive Developer Community
     
    Email me:
    Google: [email protected]

  • edited December 31, 1969
    hi,

    i want to create a dynamic marker on the x-axis:

    function beforeGeneration(chart, icsc){
    importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
    importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
    importPackage(Packages.org.eclipse.birt.chart.model.attribute);
    importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);

    var chart = icsc.getChartInstance();
    var xAxis = chart.getAxes().get(0);

    var EoD = icsc.getExternalContext().getScriptable().getParameterValue("EoD");


    top_ml = MarkerLineImpl.create(xAxis, NumberDataElementImpl.create(EoD));
    top_ml.getLabel().getCaption().setValue("EoD " + EoD);
    top_ml.getLineAttributes().getColor().set(0,200,0);
    top_ml.getLineAttributes().setStyle(LineStyle.SOLID_LITERAL);
    top_ml.getLineAttributes().setThickness(2);
    }


    the x-axis is generated out of "to_char(mydate, 'YYYY-WW')"

    the paramter has data type string and is a text box.

    thx for your help.
  • edited December 31, 1969
    hmmm



    now i changed my statement to get a date for the x-axis, he sorts the line chart correct.

    But when i want to add a dynamic marker via:

    intcountformaker = 0;



    function afterDataSetFilled( series, dataSet, icsc )

    {

    importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);

    importPackage(Packages.com.ibm.icu.util);

    //x-axis Series

    if (series.eClass().getName().equals("Series"))

    {

    var list = dataSet.getValues();



    for ( i=0; i<list.length; i=i+1)

    {

    var cdt = icsc.getExternalContext().getScriptable().getParameterValue("EoD");



    var yr = list.fieldDifference( cdt, Calendar.YEAR );

    var mn = list.fieldDifference( cdt, Calendar.MONTH );

    var dy = list.fieldDifference( cdt, Calendar.DATE );

    if( yr == 0 && mn == 0 && dy == 0){

    intcountformaker = i;

    }

    }

    }

    }



    function beforeGeneration( chart, icsc )

    {

    importPackage(Packages.org.eclipse.birt.chart.model.component.impl);

    importPackage(Packages.org.eclipse.birt.chart.model.data.impl);

    importPackage(Packages.org.eclipse.birt.chart.model.attribute);

    importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);

    var xAxis =chart.getAxes().get(0);



    target_ml = MarkerLineImpl.create(xAxis, NumberDataElementImpl.create(intcountformaker));

    //target_ml.getLabel().getCaption().setValue("EoD");

    target_ml.getLineAttributes().getColor().set(32,145,245);

    }

    he changed the dates of the x-axis to my EoD parameter - i have no idea why... :(
  • edited December 31, 1969
    now i try this:
    function beforeGeneration( chart, icsc )
    {
    importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
    importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
    importPackage(Packages.org.eclipse.birt.chart.model.attribute);
    importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);
    var xAxis =chart.getAxes().get(0);
    var EoD = icsc.getExternalContext().getScriptable().getParameterValue("EoD");
    target_ml = MarkerLineImpl.create(xAxis, NumberDataElementImpl.create(EoD));
    target_ml.getLabel().getCaption().setValue("EoD");
    target_ml.getLineAttributes().getColor().set(32,145,245);
    }


    but also failed :(

    any ideas how i cant create a dynamic marker on the x-axis for datetimes?

    thx
  • mwilliamsmwilliams BIRT Guru
    edited December 31, 1969
    What is your BIRT version? I'll try to make an example in your version.

    Regards,

    Michael Williams

    eSignLive Evangelism & Community Manager | eSignLive by VASCO
     
    Find me on:
    Twitter
    Facebook
    Blog

    LinkedIn

    eSignLive Developer Community
     
    Email me:
    Google: [email protected]

  • edited May 23, 2012
    at the moment version 2.6.2.

    thx for your help...
  • mwilliamsmwilliams BIRT Guru
    edited December 31, 1969
    Take a look at this report. I am not using the x-axis as a category axis in this example. It is an actual dateTime axis. All I did was add a marker line in the chart wizard, then since it was my only marker line, I only needed a very simple script to change the value to the entered parameter value. Let me know if this is not what you're wanting. If you're using a category axis, it'll be different.

    Regards,

    Michael Williams

    eSignLive Evangelism & Community Manager | eSignLive by VASCO
     
    Find me on:
    Twitter
    Facebook
    Blog

    LinkedIn

    eSignLive Developer Community
     
    Email me:
    Google: [email protected]

  • edited December 31, 1969
    hi,

    thx for your help.


    unfortunaly it is a category axis.
  • edited May 25, 2012
    importPackage (Packages.org.eclipse.birt.chart.model.data.impl);

    function beforeDrawMarkerLine( axis, markerLine, icsc )
    {
    if (markerLine.getLabel().getCaption().getValue() == "EoD") {
    if (icsc.getExternalContext().getScriptable().getParameterValue("EoD") != null) {
    ml = icsc.getExternalContext().getScriptable().getParameterValue("EoD");
    y = ml.getYear() + 1900;
    m = ml.getMonth();
    d = ml.getDate();
    markerLine.setValue(DateTimeDataElementImpl.create(new Date(y,m,d)));
    }
    else {
    markerLine.getLineAttributes().setVisible(false);
    markerLine.getLabel().setVisible(false);
    }
    }

    if (markerLine.getLabel().getCaption().getValue() == "Frozen"){
    if (icsc.getExternalContext().getScriptable().getParameterValue("Frozen") != null) {
    ml = icsc.getExternalContext().getScriptable().getParameterValue("Frozen");
    y = ml.getYear() + 1900;
    m = ml.getMonth();
    d = ml.getDate();
    markerLine.setValue(DateTimeDataElementImpl.create(new Date(y,m,d)));
    }
    else {
    markerLine.getLineAttributes().setVisible(false);
    markerLine.getLabel().setVisible(false);
    }
    }
    }


    But what do you mean with: category axis, it'll be different.
  • mwilliamsmwilliams BIRT Guru
    edited December 31, 1969
    Well, when it's a category axis, the marker value accepts an integer. From what I saw, when I was creating the example above, the value is for which tick on the x-axis will get the marker line, so you won't be able to pass a date for this, you'll have to figure out based on the date entered by the user how many ticks over you want the marker line to be. That's just what I assumed based on what I saw before switching to a non-category axis. I could be very wrong on that. I'll edit the above example to use a category axis and see how it goes.

    Regards,

    Michael Williams

    eSignLive Evangelism & Community Manager | eSignLive by VASCO
     
    Find me on:
    Twitter
    Facebook
    Blog

    LinkedIn

    eSignLive Developer Community
     
    Email me:
    Google: [email protected]

  • mwilliamsmwilliams BIRT Guru
    edited December 31, 1969
    Ok. Take a look at this one. The first chart is the same as the one from the example above. The second chart is with a category axis. Same explanation as above, I added the marker in the wizard and just change the value in script. I elected to do all of my script in the chart, but I'm sure you could figure out the position for the marker outside and pass it in. Maybe easier than what I had to do, in the end. :)

    Regards,

    Michael Williams

    eSignLive Evangelism & Community Manager | eSignLive by VASCO
     
    Find me on:
    Twitter
    Facebook
    Blog

    LinkedIn

    eSignLive Developer Community
     
    Email me:
    Google: [email protected]

  • edited December 31, 1969
    thanks a lot for your help - it works great :)
  • edited June 1, 2012
    one more question :)

    Is it possible via birt to create a dynamic xAxis? (scalable)

    i try something like this only as example for the yAxis (which is a number):

    function beforeGeneration( chart, icsc )
    {
    min = NumberDataElementImpl.create(100.0);
    yAxis1 = chart.primaryBaseAxes[0];
    yScale1 = yAxis1.getScale();
    yScale1.setMin(min);
    }

    but it didnt work :(
  • mwilliamsmwilliams BIRT Guru
    edited December 31, 1969

    Regards,

    Michael Williams

    eSignLive Evangelism & Community Manager | eSignLive by VASCO
     
    Find me on:
    Twitter
    Facebook
    Blog

    LinkedIn

    eSignLive Developer Community
     
    Email me:
    Google: [email protected]

  • Can the example u have given created using BIRT version 2.6 work with 4.4.2 because when i am trying to do same getting below error

    Cannot convert Invalid Date to java.lang.Long at line 34 of chart script:''

Sign In or Register to comment.