Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Dynamically changing the date format on the X axis
Dynamically changing the date format on the X axis [message #851151] Fri, 20 April 2012 13:51 Go to next message
Mike Wulkan is currently offline Mike Wulkan
Messages: 141
Registered: July 2009
Senior Member
Currently in my reports I have logic that checks whether the range of datetimes on the X axis spans a calendar day. If it does it sets the format specifier to show both the date and time, otherwise it sets the format specifier to just show the time. It does this in the beforeGeneration script for the chart using:
xAxis.setFormatSpecifier( JavaDateFormatSpecifierImpl.create(dateTimeFormat) );

What I would like to do is change this so that only the first label for a unique day gets the long format and the rest of the labels use the short time only format. This would reduce the clutter and highlight the point where the day changed.

I tried to change the format using the above API in the beforeDrawAxisLabel script but no matter what I set it to it doesn't appear to take effect. I'm thinking that I may have to define the X axis label as a string and format it myself in the beforeDrawAxisLabel.

I am hoping there is a better way

Thanks,
Mike
Re: Dynamically changing the date format on the X axis [message #851173 is a reply to message #851151] Fri, 20 April 2012 14:12 Go to previous message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Mike

Are you doing something like:


function beforeDrawAxisLabel( axis, label, context )
{
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
importPackage(Packages.java.text);
//LINEAR_LITERAL
//LOGARITHMIC_LITERAL
//TEXT_LITERAL
//DATE_TIME_LITERAL
if (axis.getType() == AxisType.DATE_TIME_LITERAL)
{
value = label.getCaption().getValue();

importPackage( Packages.java.util );
var lc = new Locale("en", "US");
var dtf2 = new SimpleDateFormat("MMM/dd/yyyy", lc);
//var dtf2 = new SimpleDateFormat("MM/dd",
context.getExternalContext().getScriptable().getLocale());
var dt = new Date(value);
var fn1 = dtf2.format(dt);
label.getCaption().setValue(fn1);

}
}

Jason


On 4/20/2012 1:51 PM, Mike Wulkan wrote:
> Currently in my reports I have logic that checks whether the range of
> datetimes on the X axis spans a calendar day. If it does it sets the
> format specifier to show both the date and time, otherwise it sets the
> format specifier to just show the time. It does this in the
> beforeGeneration script for the chart using:
> xAxis.setFormatSpecifier(
> JavaDateFormatSpecifierImpl.create(dateTimeFormat) );
>
> What I would like to do is change this so that only the first label for
> a unique day gets the long format and the rest of the labels use the
> short time only format. This would reduce the clutter and highlight the
> point where the day changed.
>
> I tried to change the format using the above API in the
> beforeDrawAxisLabel script but no matter what I set it to it doesn't
> appear to take effect. I'm thinking that I may have to define the X axis
> label as a string and format it myself in the beforeDrawAxisLabel.
> I am hoping there is a better way
>
> Thanks,
> Mike
Previous Topic:Setting data using JavaScript on BIRT DE
Next Topic:How can I retrieve data?
Goto Forum:
  


Current Time: Tue Jul 29 23:05:47 EDT 2014

Powered by FUDForum. Page generated in 0.09437 seconds