Home
Analytics
[Solved] BIRT Chart Dynamic X Axis DataSet
GaidenFocus
<p>Howdy!</p>
<p> </p>
<p>I am looking for a way to change the data set assigned to the X axis of my chart based on the value of a parameter. </p>
<p> </p>
<p>I need to know the command to change the data set in the x axis on my chart. Thanks!</p>
Find more posts tagged with
Comments
pricher
<p>Hi,</p>
<p> </p>
<p>Can you explain a bit more what you are attempting to accomplish? Changing the binding of chart to a data set is not trivial (I suspect it involves using the Report Design API) and it will have an impact on the chart design if the two data sets are different.</p>
<p> </p>
<p>Regards,</p>
<p> </p>
<p>P.</p>
GaidenFocus
<p>Same data set different view. I have locations, projects, and date. I want to be able to tell it which one to use for the X axis. I have found plenty of API commands for adding and removing Y series, but nothing on the X axis. I do NOT want to make separate reports haha. When I change the X Axis by hand from row["date"] to row["location"] or row["project"] it works just fine. I want a script to look at a parameter I send it and determine which row to use for the X axis. Thanks! </p>
pricher
<p>Hi,</p>
<p> </p>
<p>Could that be as simple as replacing the expression</p>
<p> </p>
<p><span style="font-family:'courier new', courier, monospace;">row["X_Axis_Column"]</span></p>
<p> </p>
<p>in the X-Axis definition of the Chart with</p>
<p> </p>
<p><span style="font-family:'courier new', courier, monospace;">row[params["pAxis"].value]</span></p>
<p> </p>
<p>where <span style="font-family:'courier new', courier, monospace;">pAxis </span>is a string parameter that returns the name of the X_Axis_Column?</p>
<p> </p>
<p>Example attached.</p>
<p> </p>
<p>P.</p>
<p> </p>
<p> </p>
GaidenFocus
<p>I actually just tried that, I think the issue is with the data type. For date it needs datetime, the others string. Do you know of a way to change the X Axis data type? </p>
GaidenFocus
<p>I just found another post</p>
<p> </p>
<div>switch (params["X Axis"].value)</div>
<div>{</div>
<div>case 'date' : row["date"];</div>
<div>break;</div>
<div>case 'location' : row["location"];</div>
<div>break;</div>
<div>case 'project' : row["project"];</div>
<div>default : </div>
<div>break;</div>
<div> </div>
<div>}</div>
<div> </div>
<div>EDIT: Ok I posted this too soon, does not work. Changed the ' to " set the data type to text and toggled location to project (both text). This did not work. =(</div>
GaidenFocus
<p>UPDATE</p>
<p> </p>
<div>switch (params["xaxis"].value)</div>
<div>{</div>
<div>case "date": row["date"]; break;</div>
<div>case "location": row["location"]; break;</div>
<div>case "project": row["project"]; break;</div>
<div>}</div>
<div> </div>
<div>This works, but the issue i mentioned earlier persists. I need to toggle type from text to date. Thanks for the help!</div>
pricher
<p>Hi,</p>
<p> </p>
<p>Here's a better example. Scripting is in two places:</p>
<p> </p>
<p>1. in the beforeFactory of the report to change the grouping unit of the chart if it is grouped by date;</p>
<p>2. in the beforeGeneration of the chart to change the date format on the X-Axis</p>
<p> </p>
<p>Hope this helps,</p>
<p> </p>
<p>P.</p>
GaidenFocus
<p>Awesome I got it to work on my chart, thanks a bunch for your help.</p>
<p> </p>
<p> </p>
<p></p><pre class="_prettyXprint _linenums:0">
//beforeFactory on Form
var axisGroup = reportContext.getParameterValue("xaxis");
chart = this.getReportElement("report_chart");
if (axisGroup == "date")
{
chart.getCategory().getGrouping().setGroupType("DateTime");
}
//on the chart script
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("MM/yy") );
}
}
//in the x axis expression builder
switch (params["xaxis"].value)
{
case "date": row["date"]; break;
case "location": row["location"]; break;
case "project": row["project"]; break;
}
</pre>
GaidenFocus
<p>I have one more issue with the DateTime format.</p>
<p> </p>
<p><a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/topic/35559-date-format/'>http://developer.actuate.com/community/forum/index.php?/topic/35559-date-format/</a></p>
;
sudata
<p>Hi,</p>
<p>Since long time i am searching for an issue which i couldn't find a solution. Please can i get a solution for that?</p>
<p> </p>
<p>As mentioned in the above posts grouping for X-Axis is possible using a parameter and the script in beforeFactory.</p>
<p>But i should not give access to the end user to select the parameter. I should hide the parameter but its value should be changed dynamically.</p>
<p>The parameter should be changed dynamically based on the row value which is obtained in the dataset. (what script i should write and where)</p>
<p> </p>
<p>Going deep into the issue...</p>
<p>I have a dataset with few columns, in which one column is "maximum date value" and one column is "minimum date value" and the third column is "time period"... (like if "max - min > 30" then the value of this column should be "months" and if "max - min < 30" then that column value will be "Days")...these three columns values will be changed dynamically based on the data...</p>
<p>So now based on the value of the third column the parameter has to be changed dynamically...</p>
<p>Like if the third column is "months" then the parameter value should be months and the x-axis should be grouped accordingly, likewise if the column value is years then group x-axis based on years...\</p>
<p>So to accomplish this which script i should write and where i should write the script.</p>
<p> </p>
<p>Please can anyone get a solution for this... That would be great help for me if i get a solution for this...</p>
<p> </p>
<p>Thank you,</p>
<p>Subbu.</p>