Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Change date format in Charts dinamically
pavlicic
Hi everybody,
I would like to change date format in a chart using Javascript. The thing i would like to do is to have a format stored in Javascript file and use that format as base format in charts, so if final user decide to change date format, they just need to change that file and not 100 reports.
Do you think it is possible? Also, the reason is that we create the query dinamically (field time) based in a parameter called Periodlength. The idea is, if periodlenght is less than 1 hour, we show data per 15 minutes (row level), if it is less than 1 day, we show data per hour, and if it is greater than a day, we show data per day. Using this, we want to change formats dinamically (in day format, we don't want to use time)
Thanks in advance
Find more posts tagged with
Comments
kretes
You may add a JS file to the report.
Don't know will it work and how it stores the location of JS file, but You can - select your report file, and see view property editor - report, and tab Properties|Resources - there You go. good luck
pavlicic
thanks for your answer, but i need like a code example to access the format on X-axis on a chart... dont know if it possible
pavlicic
hi,<br />
<br />
I think I know now how to do it but i am having an error with AxisType. My code is:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeDrawAxisLabel(axis, label, icsc)
{
if (axis.getType() == AxisType.DATE_TIME_LITERAL){
var actualval = "" + label.getCaption().getValue();
var sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm");
var dateval = sdf.parse(actualval);
label.getCaption().setValue( sdf.format(dateval) );
axis.setLabel(label);
}
}
</pre>
<br />
in a chart. The error is that AxisType is not defined. What do i have to import? I can't get this stuff working.<br />
<br />
Thanks in advance
mwilliams
Hi pavlicic,
Try adding this:
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
This should do it.
pavlicic
Hi,<br />
<br />
Thanks for your answer. Now it works perfectly. This is the final code for BIRT 2.2.1 in the OnRender event of a chart:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.java.text);
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
/**
* Called before rendering each label on a given Axis.
*
*
@param
axis
* Axis
*
@param
label
* Label
*
@param
icsc
* IChartScriptContext
*/
function beforeDrawAxisLabel(axis, label, icsc)
{
if (axis.getType() == AxisType.DATE_TIME_LITERAL){
var actualval = "" + label.getCaption().getValue();
var sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
var dateval = sdf.parse(actualval);
sdf.applyPattern("MM/dd/yyyy HH:mm");
label.getCaption().setValue( sdf.format(dateval) );
axis.setLabel(label);
}
}
</pre>
<br />
The idea is now store the formats (both) in a file. I am researching this, but I think we will store those formats in the resources files as kretes said, we can not access variables stored in JS files from this event.<br />
<br />
Thanks a million for your answers, it helped a lot. Hope another people can think this code is useful
robertl
just what I was looking for