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)
Changing X Axis Data Type
GaidenFocus
<p>Last question about the X Axis on the chart! (After this I promise to pass on this information to others who are looking for this info!)</p>
<p> </p>
<p>I have the dynamic time interval working great when the data type on the X Axis is DateTime. However I have two other options that would require the X Axis to be Text. </p>
<p> </p>
<p>Tried this...did not work (I tried it in before factory, and before generation..still not sure what is what when it comes to that)</p>
<p></p><pre class="_prettyXprint _linenums:0">xAxis.setType(AxisType.TEXT_LITERAL);
</pre>
<p> </p>
<p>Anyone know what I need to tell it to change it to the text type?</p>
Find more posts tagged with
Comments
mwilliams
I'm not sure I'm understanding the issue. Could you explain in a little more detail? Thanks!
GaidenFocus
<p>Sure! What I have is a UI that lets the user select weither they want the chart to be by Location, Project, or Date which will change the X Axis. I was able to get it to work until I added the grouping change. This now allows the user to choose Day, Week, Month, Quarter, or Year. This works but it did not allow me to do the Location or Project options. This is because the charts X Axis had to be changed from Text to DateTime. Originally I was able to get it to convert it from Text to DataTime, but to get the time period selector to work I had to change it to DateTime by default breaking the Text options.</p>
<p> </p>
<p>I still don't know exactly what exists when the different events fire (beforeFactory, afterFactory, etc) nor the API commands regarding the chart (or most other things for that matter)<br><br>
I know that I can make multiple copies of the chart to get it working...one Text, one DateTime on the X Axis but I absolutely do not want to do that simply because of the programmers credo (turn 10 lines of code in to 1! or in this case, 1 report for all needs!)</p>
<p> </p>
<p>So I have a beforeFactory event that determines the users selection and changes the chart accordingly. I need to know when and how to change the X Axis to the text format so that it can handle the Location and Project options.</p>
mwilliams
The easiest solution would be to create the chart in all three ways and just drop the unneeded ones based on the parameter. You can drop the unnecessary charts in the beforeFactory.
mwilliams
If that's not an option you'd like to go with, let me know and I'll help you write the code to change the chart through script or build it from scratch based on the parameters selected.
GaidenFocus
<p>Yea I thought about multiple charts but that sounds like a pain if I needed to make a change (which would be across multiple files...i want to keep charts at Reports * 1 rather than Reports * 2)</p>
<p> </p>
<p>I feel like that line of code I posted should do the trick I may just have it in the wrong place.</p>
<p> </p>
<p>Before i added the grouping selector it worked fine between text and date time.</p>
<p> </p>
<p>The following code used to check if the xaxis param was "Date" or not and then change the charts X Axis to DateTime instead of Text. This worked great until I added the grouping. I then set the charts to DateTime and changed this to see if it is NOT "Date" and then change it to text if not, but that does not work. I am assuming it is already set, or rather the beforeFactory code on the main page is overwriting this. I did however try to add in similar code to the beforeFactory code which does not work either.</p>
<pre class="_prettyXprint _linenums:0">
//IN THE CHART
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.setType(AxisType.TEXT_LITERAL);
}
}
//IN THE LAYOUT BEFORE FACTORY
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;
chart = reportContext.getDesignHandle().findElement("report_chart");
report_chart = chart.getReportItem().getProperty("chart.instance");
xAxis = report_chart.getBaseAxes()[0];
if (param == "Date")
{
xAxis.setType(AxisType.DATE_TIME_LITERAL);
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);
}
else
{
xAxis.setType(AxisType.TEXT_LITERAL);
}
</pre>
GaidenFocus
<p>So I compared the XML when changing between DateTime and Text on the X Axis and it's just one line. I'm going to parse the XML before I even open the file. Thanks for trying!</p>
mwilliams
<p>Sorry I wasn't able to get this looked at sooner. If your current solution doesn't work out for you, I attached a report that allows the user to choose an x-axis category (Date, Integer, or String). There is also a parameter for choosing grouping level of the date.</p>
<p> </p>
<p> </p>
GaidenFocus
<p>I used TextPad to compare the XML changes between Text and DateTime on the X Axis. It was only one line...i made a function in PHP that will change that one line to Text if Date was not selected. I did try your code (after modifying it for my report of course) and that didn't work. I may just do XML modification from here on out it is a bit easier than trying to figure out what when and where to put the scripting. (I also have a hard time finding API commands, or rather a detailed explanation as to what they do.)</p>
mwilliams
If your solution works, it's probably just fine. Are you getting an error that you can post? It may have something to do with the grouping, not with the axis. If you're okay with doing it the way you know it's working, I'd just go with that.
GaidenFocus
<p>In case anyone is looking for a solution via PHP here is the code I'm using</p>
<pre class="_prettyXprint _linenums:0">
$chart = simplexml_load_file($template, 'SimpleXMLElement', LIBXML_NOCDATA);
$chart = simplexml_load_string($this->Chart->body->{'extended-item'}->{'xml-property'}[0]);
$chart->Axes->SeriesDefinitions->Grouping->GroupType->{0} = 'Text';
</pre>
<p>It did not give me an error message when I tried your code, just a blank report. Is there a way to go behind the scenes and get some sort of error log?</p>
mwilliams
There are logs, but you'd likely get an error in the UI if there was something messed up with how you set things up. Was just wondering.