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)
How to show few month values on graph with 12 month time line
vraaijmakers
<p>Hi, we designed a graph for our customer that shows values of a year.</p>
<p>So the x-axis displays the 12 months.</p>
<p> </p>
<p>We currently have only values for the month of jan and feb, so after that the graph drops to 0.</p>
<p>Question we got is, to just stop displaying values after February.</p>
<p> </p>
<p>Is that possible?</p>
Find more posts tagged with
Comments
JFreeman
<p>It looks like you have two series on this chart.</p>
<p>Does the other series contain data for all 12 months?</p>
vraaijmakers
<p>Hi Jesse, yes it does.</p>
JFreeman
<p>Thank you for the confirmation.</p>
<p> </p>
<p>Which version of BIRT are you using?</p>
<p>What type of chart are you using (SVG, PNG, HTML, etc)?</p>
<p> </p>
<p>Is it possible for you to attach a sample report with a flat file data source that we can run to replicate the issue?</p>
vraaijmakers
<p>Hi Jesse, I can send you the report, however it will take me some time to create a data model.</p>
<p>Report is very complex using multiple sources (Excel, mySQL, SQLServer)</p>
<p> </p>
<p>Not sure if I understand your type of Graph question, this is just the graph selection from the palette.</p>
<p> </p>
<p> </p>
<p>This is what I use on the mac:</p>
<p><span style="font-family:'Helvetica Neue';font-size:11px;">Actuate BIRT Designer Professional </span></p>
<p style="font-size:11px;font-family:'Helvetica Neue';">Version: 4.4.0</p>
<p style="font-size:11px;font-family:'Helvetica Neue';">Build id: v20150206</p>
JFreeman
<p>Thank you for the confirmation on your BIRT Version.</p>
<p> </p>
<p>Regarding the chart type, on the first page of the chart builder dialogue after adding it to the report, there is a drop down to select the chart type, labeled as Output Format. In the version you are using the choices are: HTML, PNG, JPG, BMP, and SVG.</p>
<p> </p>
<p>The default type in the version you are using with be HTML.</p>
<p> </p>
<p>Please let which format you are using. I think what you want to accomplish should be possible through some scripting and the scripting needed will be different depending on the format you are using.</p>
vraaijmakers
<p>Ah I see, thanks. Yes it is set to HTML5.</p>
JFreeman
<p>With an HTML5 chart, you can use javascript in the afterRendering of the chart scripts to trim the first series that has data points at 0 and then trim the second series to align with the first series.</p>
<p> </p>
<p>For example:</p>
<pre class="_prettyXprint _lang-js">
afterRendering: function(chart)
{
function trimFirstSeries(){
var pointNumber = chart.getCore().series[0].data.length;
var pointsToRemove = []
var count = 0;
for(var i=0; i<pointNumber; i++){
var point = chart.getCore().series[0].data[i];
if(point.y == 0){
pointsToRemove[count] = i;
count++;
}
}
for(var x=(count-1); x>=0; x--){
if(x == 0){
//Rerender chart on the last point to be removed.
chart.getCore().series[0].data[pointsToRemove[x]].remove(true);
}else{
//Do not rerender chart yet.
chart.getCore().series[0].data[pointsToRemove[x]].remove(false);
}
}
return chart.getCore().series[0].data.length;
}
function alignSecondSeries(firstSeriesLength){
var secondSeriesLength = chart.getCore().series[1].data.length;
for(var i=(secondSeriesLength-1); i>=firstSeriesLength; i--){
if(i == (firstSeriesLength)){
chart.getCore().series[1].data[i].remove(true);
}else{
chart.getCore().series[1].data[i].remove(false);
}
}
}
var newSeriesLength = trimFirstSeries();
alignSecondSeries(newSeriesLength);
},
</pre>
<div><br><p> </p>
</div>
<div>Take a look at the attached example for reference. I have created two charts. One with the code to trim the x axis and one without to illustrate the change.</div>
vraaijmakers
<p>Hi Jesse, thanks for the script! Initially I thought the script was working but then I realized that the data you use is not 100% of what I have.</p>
<p>When I change the data in your expel I get only the lines for the months that have value.</p>
<p> </p>
<p>Something you can fix you think?</p>
<p> </p>
<p>So my data looks like this:</p>
<p> </p>
<p>mon val1 val2</p>
<p>1.00 75 40</p>
<p>2.00 35 40</p>
<p>3.00 0 0</p>
<p>4.00 0 0</p>
<p>5.00 0 0</p>
<p>6.00 0 0</p>
<p>7.00 0 0</p>
<p>8.00 0 0</p>
<p>9.00 0 0</p>
<p>10.00 0 0</p>
<p>11.00 0 0</p>
<p>12.00 0 0</p>
vraaijmakers
<p>Jesse, sorry I realized this morning that your script should actually work. My data looks kind the same as your example. Will investigate and let you know. </p>
JFreeman
<p>Alright, let me know if you have additional questions.</p>
vraaijmakers
<p>Jesse,I'm not sure how your example worked in your environment, but if I run it, the HTML only shows month 1 and 2 on the x-axis.</p>
<p>I would expect to see the values for</p>
<p> </p>
<p>val1: months 1-2 and</p>
<p>val2: months 1-12</p>
<p> </p>
<p>Correct?</p>
<p> </p>
<p>Vincent</p>
JFreeman
<p>I think I misunderstood your requirement.</p>
<p> </p>
<p>I was thinking you wanted to trim the entire chart to only show months where the both series had data.</p>
<p> </p>
<p>If you only want to trim the first series and leave the second series to display all 12 months, remove the function "alignSecondSeries" and then only call the first function "trimFirstSeries".</p>
<p> </p>
<p>Something like:</p>
<pre class="_prettyXprint _lang-js">
afterRendering: function(chart)
{
function trimFirstSeries(){
var pointNumber = chart.getCore().series[0].data.length;
var pointsToRemove = []
var count = 0;
for(var i=0; i<pointNumber; i++){
var point = chart.getCore().series[0].data[i];
if(point.y == 0){
pointsToRemove[count] = i;
count++;
}
}
for(var x=(count-1); x>=0; x--){
if(x == 0){
//Rerender chart on the last point to be removed.
chart.getCore().series[0].data[pointsToRemove[x]].remove(true);
}else{
//Do not rerender chart yet.
chart.getCore().series[0].data[pointsToRemove[x]].remove(false);
}
}
}
trimFirstSeries();
},
</pre>
vraaijmakers
<p>Bingo! Thank you so much, this is exactly what I was looking for!</p>
<p> </p>
<p>Very much appreciated!! </p>
JFreeman
<p>You're welcome.</p>
<p>I'm glad I could be of assistance.</p>
<p> </p>
<p>Let us know if you have any additional questions.</p>