BIRT Exchange Forum: Setting min & max on X-axis to a time parameter - BIRT Exchange Forum

Jump to content


 

No Latest Open Poll.

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Setting min & max on X-axis to a time parameter Rate Topic: -----

#1 User is offline   zax Icon

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 70
  • Joined: 09-August 10


Posted 15 May 2012 - 02:09 AM

I have a report with two time parameters, and I want them to define the maximum and minimum X axis scale in a chart. I have found this that describes how to do it with dates, but I am unable to figure out how to do it with times.

This is my latest effort:
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);

function beforeGeneration( chart, icsc )
{

	/* This script will change the Min and Max value of the X axis based on the value
	   for the Start and End date parameters. 
	   NB: In order to work, make sure to turn OFF the "Is Category Axis" attribute
	   in the X-Axis properties screen
	*/

	/* Get the start and end dates from the parameters */
	start_time_p = icsc.getExternalContext().getScriptable().getParameterValue("start_time");
	finish_time_p = icsc.getExternalContext().getScriptable().getParameterValue("finish_time");

	start_time = new Date( (start_time_p.getHours() + 1) + ":" + start_time_p.getMinutes() + ":" + start_time_p.getSeconds() );

	/* Get the X-Axis object */
    xAxisArray = chart.getBaseAxes();

	/* Set the Min and Max values */
    xAxisArray[0].getScale().setMin(DateTimeDataElementImpl.create(start_time));
}


But I understand that the constructor of a date object requires a long integer, which is probably why I get this error:

Cannot convert Invalid Date to java.lang.Long at line 34 of chart script:'' (Element ID:71)


Any help getting this working will be very much appreciated,

Thanks,
Stephen
0

#2 User is offline   mwilliams Icon

  • BIRT Guru
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 12971
  • Joined: 16-May 08


Posted 17 May 2012 - 07:47 AM

So, the report runs only for the current day, between the times entered in the parameters? Is this correct? Let me know. Also, let me know your BIRT version. Thanks.
Regards,

Michael

Twitter
Facebook
Blog
Yahoo: mwilliams_actuate@yahoo.com
Google: mwilliams.actuate@gmail.com
0

#3 User is offline   zax Icon

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 70
  • Joined: 09-August 10


Posted 18 May 2012 - 12:27 AM

Yes, exactly. Let's say between 07:00:00 and 08:00:00 on a single day.

I have even tried hard coding a long integer when creating the date objects:

	start_time = new Date(1337119200000);
	finish_time = new Date(1337205600000);

	// Get the X-Axis object 
        xAxisArray = chart.getBaseAxes();

	// Set the Min and Max values 
        xAxisArray[0].getScale().setMin(DateTimeDataElementImpl.create(start_time));
        xAxisArray[0].getScale().setMax(DateTimeDataElementImpl.create(finish_time));  



and I get the axis drawn, no errors, but no line chart either. Maybe the line chart is outside the time axis I have defined, but I did make sure the long int time was the same as the parameters passed in.

I hope this makes sense...

My Birt version is 3.7.2.

Stephen


View Postmwilliams, on 17 May 2012 - 08:47 AM, said:

So, the report runs only for the current day, between the times entered in the parameters? Is this correct? Let me know. Also, let me know your BIRT version. Thanks.

0

#4 User is offline   mwilliams Icon

  • BIRT Guru
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 12971
  • Joined: 16-May 08


Posted 21 May 2012 - 09:31 AM

Take a look at this example.

Attached File(s)


Regards,

Michael

Twitter
Facebook
Blog
Yahoo: mwilliams_actuate@yahoo.com
Google: mwilliams.actuate@gmail.com
0

#5 User is offline   zax Icon

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 70
  • Joined: 09-August 10


Posted 22 May 2012 - 12:45 AM

Thanks for your reply. This is closer to what I am trying to achieve. But I notice the hour parameters that are selected are integers. The data sets I am dealing with have one second intervals, so it is feasible that the start and stop times could be: 07:10:00 and 07:10:40 on a selected day.

I was thinking of adding the BIRT time parameter to the date object constructor. This will give the user total flexibility.

Another option is to take the time and convert it to seconds from midnight and add it to the date (converted to seconds from the epoch). Java is not (yet) my strong suit, so any help or advice is much appreciated.
0

#6 User is offline   mwilliams Icon

  • BIRT Guru
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 12971
  • Joined: 16-May 08


Posted 22 May 2012 - 06:14 AM

Here's the same report, only using times, hh:mm:ss, as the parameter values. Hope this helps.

Attached File(s)


Regards,

Michael

Twitter
Facebook
Blog
Yahoo: mwilliams_actuate@yahoo.com
Google: mwilliams.actuate@gmail.com
0

#7 User is offline   zax Icon

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 70
  • Joined: 09-August 10


Posted 23 May 2012 - 11:13 PM

Very helpful thanks. I decided to go the millisecond way though:

function beforeGeneration(chart, icsc)
{
	importPackage( Packages.org.eclipse.birt.chart.model.data.impl );
	importPackage( Packages.org.eclipse.birt.chart.util );
	
	// Get the x axis.
	xAxis = chart.getBaseAxes()[0];
	scale = xAxis.getScale();
	
	// Grab the day, start and finish time parameters.
	s_date_p = icsc.getExternalContext().getScriptable().getParameterValue("day");
	start_time_p = icsc.getExternalContext().getScriptable().getParameterValue("start_time");
	finish_time_p = icsc.getExternalContext().getScriptable().getParameterValue("finish_time");	

	// Add the times to the day (as milliseconds) and it seems a timezone offset needs to be used.
	start = new Date(s_date_p.getTime() + start_time_p.getTime() - (start_time_p.getTimezoneOffset() * 60000) );
	finish = new Date(s_date_p.getTime() + finish_time_p.getTime() - (start_time_p.getTimezoneOffset() * 60000) );
	
	// Apply the new times to the start and end of the x axis.
	scale.setMin( DateTimeDataElementImpl.create(start) );
	scale.setMax( DateTimeDataElementImpl.create(finish) );
}



The UTC offset I found confusing... I am at +1 GMT (CEST), but I think this correct. Without that adjustment the time used by the axis is 1 hour earlier.

Anyway, the chart now behaves like this when the start time parameter is set to 05:00:00
Attached File  chart.png (26.24K)
Number of downloads: 6

Thanks for all your help :)
0

#8 User is offline   mwilliams Icon

  • BIRT Guru
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 12971
  • Joined: 16-May 08


Posted 24 May 2012 - 12:05 PM

So, the data is supposed to be shifted over an hour earlier? Or is the data just missing? Since I can't see the data, I don't know what you're expecting. :) Let me know!
Regards,

Michael

Twitter
Facebook
Blog
Yahoo: mwilliams_actuate@yahoo.com
Google: mwilliams.actuate@gmail.com
0

#9 User is offline   zax Icon

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 70
  • Joined: 09-August 10


Posted 25 May 2012 - 02:13 AM

There is no data before where the chart has started drawing the line. But I had the request to have a parameter set time axis so the user can see when the data starts and that there was definitely no data before then.

Also, the parameter set time span produces an easier to read scale and gridlines..Intervals between

06:00:00 and 08:00:00

are easier to understand than between (for example)

06:23:39 and 07:45:33

when the engine draws the chart based upon available data.
0

#10 User is offline   mwilliams Icon

  • BIRT Guru
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 12971
  • Joined: 16-May 08


Posted 01 June 2012 - 07:40 AM

Sorry for the delay. I had been working on a project that didn't allow me to get back in here, this week. Do you have what you're wanting, now? Or is this still an issue? Are you wanting there to be less space between the minimum scale value and the actual start of the data? Would using the minimum value of the data to determine how far back to set the scale be helpful? Let me know.
Regards,

Michael

Twitter
Facebook
Blog
Yahoo: mwilliams_actuate@yahoo.com
Google: mwilliams.actuate@gmail.com
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users