Dynamically changing the date format on the X axis [message #851151] |
Fri, 20 April 2012 13:51  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.04111 seconds