Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Date Time Chart...by Day, by Month, and by Year
GaidenFocus
<p>I have a chart report that allows the user to select the "view" as in, weither the X-Axis is broken up by date, project, or location. I now need to be able to choose between by Day, by Month, or by Year.</p>
<p> </p>
<p>I know how to set this up manually but the user will not have access to this. Any ideas on how to change the 'Group and sorting' properties via java/javascript?</p>
Find more posts tagged with
Comments
GaidenFocus
<p>I found some other code but can't get it to work right.</p>
<p> </p>
<p></p><pre class="_prettyXprint _linenums:0">beforeFactory
{
importPackage(Packages.org.eclipse.birt.chart.model);
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
if (params["xaxis"].equals("Date"))
{
chart = this.getReportElement("report_chart");
chart.getCategory().getGrouping().setGroupType("DateTime");
item = chart.getReportItem();
cm = item.getProperty("chart.instance");
xAxis = cm.getAxes().get(0);
xSeriesDef = xAxis.getSeriesDefinitions().get(0);
xGrouping = xSeriesDef.getGrouping();
if (params["view_by"].equals("Days"))
{
xGrouping.setGroupingUnit(GroupingUnitType.DAYS_LITERAL);
}
else if (params["view_by"].equals("Months"))
{
xGrouping.setGroupingUnit(GroupingUnitType.MONTHS_LITERAL);
}
else if (params["view_by"].equals("Years"))
{
xGrouping.setGroupingUnit(GroupingUnitType.YEARS_LITERAL);
}
}
}
</pre>
Clement Wong
<p>Attached is a working example. The code is in the <em>beforeFactory </em>event.</p>
GaidenFocus
<p>Thanks for the post. The code looks good in theory but is not working. The charts x axis is set to text...if i pass in the word date to the xaxis param it changes to a datetime format. Would this interfere with the function you sent me? If so then I would need to know the code to change it to text if xaxis != "Date". Thanks again!</p>
<p> </p>
<p></p><pre class="_prettyXprint _linenums:0">//IN THE CHART ITSELF
function beforeGeneration( chart, icsc )
{
importPackage( Packages.org.eclipse.birt.chart.model.attribute.impl );
importPackage( Packages.org.eclipse.birt.chart.model.attribute );
var axisGroup = icsc.getExternalContext().getScriptable().getParameterValue("xaxis");
xAxis = chart.getBaseAxes()[0];
if (axisGroup == "Date")
{
xAxis.setFormatSpecifier(JavaDateFormatSpecifierImpl.create("LLLL yyyy"));
}
}
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
importPackage(Packages.org.eclipse.birt.chart.model.type.impl);
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
param = params["xaxis"].value;
//IN THE LAYOUT SCRIPT (beforeFactory)
if (param == "Date")
{
cht = reportContext.getDesignHandle().findElement("report_chart");
mychart = cht.getReportItem().getProperty("chart.instance");
xAxis = mychart.getBaseAxes()[0];
xGrouping = xAxis.getSeriesDefinitions().get(0).getGrouping();
view_by = params["view_by"].value;
if(view_by == "Day")
{
xGrouping.setGroupingUnit(GroupingUnitType.DAYS_LITERAL);
}
else if(view_by == "Week")
{
xGrouping.setGroupingUnit(GroupingUnitType.WEEKS_LITERAL);
}
else if(view_by == "Month")
{
xGrouping.setGroupingUnit(GroupingUnitType.MONTHS_LITERAL);
}
else if(view_by == "Quarter")
{
xGrouping.setGroupingUnit(GroupingUnitType.QUARTERS_LITERAL);
}
else if(view_by == "Year")
{
xGrouping.setGroupingUnit(GroupingUnitType.YEARS_LITERAL);
}
xGrouping.setGroupingInterval(1);
}
//IN THE XAXIS EXPRESSION BUILDER
switch (params["xaxis"].value)
{
case "Date": row["date"]; break;
case "Location": row["location"]; break;
case "Project": row["project"]; break;
}
</pre>
GaidenFocus
<p>Ok so I figured out that the fact that it is text by default is the issue. It tries to run that code BEFORE changing it to DateTime. I now either need the command to change the X Axis to text OR a way to change the grouping after changing it to DateTime. I think the text option would be easier.</p>