Home
Analytics
Delete Y-Axis series at runtime from chart
crowt999
All,
I have a bar chart set up with 4 series on the Y-axis. In some instances, I will only have data to fill up 3 of the series, and in that case, I would like to delete the 4th series from the chart. I have the following code that will set any series I need to visible(false), but that still leaves the empty space where the bars used to be. I would like to be able to delete it entirely at run-time so that the space is reclaimed and the chart looks nice.
Here is my function that I can hide a series with: right now it sets the first and second series to invisible.
Is it possible to delete the runtimeseries ?
function beforeGeneration( chart, icsc )
{
var xAxis = chart.getAxes().get(0);
var yAxis = xAxis.getAssociatedAxes().get(0);
var ySeriesDef1 = yAxis.getSeriesDefinitions().get(0);
var ySeries1 = ySeriesDef1.getRunTimeSeries();
var RunSeries1 = ySeries1.get(0);
RunSeries1.setVisible(false);
var ySeriesDef2 = yAxis.getSeriesDefinitions().get(1);
var ySeries2 = ySeriesDef2.getRunTimeSeries();
var RunSeries2 = ySeries2.get(0);
RunSeries2.setVisible(false);
}
Thanks in advance for any help !
Dean
Find more posts tagged with
Comments
mwilliams
Hi Dean,
This post from the devShare shows how to add a series to a chart at runtime. I would imagine that removing a series would be very similar. Let me know if this doesn't help.
http://www.birt-exchange.org/org/devshare/designing-birt-reports/569-dynamically-add-a-series-to-a-chart/
crowt999
I could not figure out how to delete from this example, and many others I've searched the internet for, so I decided to add the series as I need them... All is going well so-far, I just need to now change the font and size of the default label that is added to the chart... Also the color - how that I think about it...
Still hacking away...
Dean
mwilliams
Dean,
Well, if that works for you, I won't look any further into the deleting of a series. Let me know if you have any questions!
crowt999
I was able to set the font and the size using the added code in the following:
var sdNew = SeriesDefinitionImpl.create();
var bs = BarSeriesImpl.create();
bs.getLabel().setVisible(true);
var newLab = bs.getLabel();
newLab.caption.font.name="Trebuchet MS";
newLab.caption.font.size="7.0";
var qry = QueryImpl.create("row[\"" + "BENCH_RETURN2" + "\"]" );
bs.getDataDefinition().add(qry);
sdNew.getSeries().add( bs );
yAxis.getSeriesDefinitions().add( sdNew );
Still stuck on 2 more things: adding a "%" suffix to the label and setting the colors of the individual series...
I have the following code that sets the ALL of the bars to the same color, but need some assistance in differentiating the series... Any Ideas ? what properties of dph are there ?
function beforeDrawDataPoint( dph, fill, icsc )
{
fill.set(37,82,130);
}
mwilliams
You can check for each series with code like:
if (dph.getSeriesDisplayValue() == "SeriesName"){
fill.set(35,70,140);
}
As for adding the %. Where are you trying to add this? In the legend or on the axis?
crowt999
I attached the image of the chart. I think it is the label...
That is where I need the % (You see the third on is missing)
I will try to set the color using your other suggestion... Thanks again!
Dean
mwilliams
So, the actual series label is getting cut off? partially? Is this the issue?
crowt999
No - not that.. The numbers are -6.47%, -6.73% and -6.469 - not rounded to 2 decimals, and no % sign...
Thanks is the issue
mwilliams
Oh, I thought that the 9 was the first circle and slash from the % sign. The picture is blurry. How are you going about formatting your labels? In script or in the chart editor?
crowt999
I need to format the label in the script where I add the new series... Code posted above that adds the series..
mwilliams
Dean,
Script that is something like the following in your chart script should do what you're wanting.
function beforeDrawDataPointLabel( dph, label, icsc )
{
newLabel = dph.getOrthogonalValue();
newLabel = parseFloat(newLabel);
newLabel = newLabel.toFixed(2);
newLabel = newLabel.toString() + "%";
label.getCaption().setValue(newLabel);
}
Hope this helps.
crowt999
Michael - "label" is unknown in context of this function. That is the only error I am still getting.
I'm thinking that I can get to the label of the series starting from icsc.getProperty( ), but am unsure what to put as the property.. still hacking away... - and continued thanks for the help...
Dean
mwilliams
Dean,
It's not an unknown context of the function that it's used in above. Why can you not format the data point label in the function I used?
crowt999
My Bad - I thought it was still drawdatapoint... I did not notice it was a diff function...
Thanks!
mwilliams
It's quite alright. Glad to help. Let us know whenever you have questions.