In the BeforeGeneration chart event you can get access to the chart design time series to turn its visibility off. When you use the chart builder to construct a chart with axes with multiple series, a series definition is created for each. So for example if you define a chart with axes that has two series (bar and line) you get two series definitions. You can turn one or the other off by using the following script:
function
beforeGeneration(chart, icsc)
{
var
xAxis = chart.getAxes().get(0);
var
yAxis = xAxis.getAssociatedAxes().get(0);
//0 - line series
//1 - bar series
//yAxis.getSeriesDefinitions().get(0).getSeries().get(0).setVisible(false);
yAxis.getSeriesDefinitions().get(1).getSeries().get(0).setVisible(
false
);
}
<br />
If you are using a chart that has optional grouping enabled it will generate multiple runtime series and the above method will turn off all the runtime series defined in the one series definition. So if you have a line chart that has an amount a category and is also grouped on month this one series definition will generate many runtime series. You can turn just one of these off by using its index.
function
beforeGeneration( chart, icsc )
{
var
xAxis = chart.getAxes().get(0);
var
yAxis = xAxis.getAssociatedAxes().get(0);
var
yseriesDef = yAxis.getSeriesDefinitions().get(0)
//first runtime series
//yseriesDef.getRunTimeSeries().get(0).setVisible(false);
//second runtime series
yseriesDef.getRunTimeSeries().get(1).setVisible(
false
);
//third runtime series
//yseriesDef.getRunTimeSeries().get(2).setVisible(false);
}
This will not turn off the legend which requires you to write a script for the before and after drawlegend items as shown below.
//store values to move legend items to fill hole
boundsH=0;
boundsW=0;
boundsT=0;
boundsL=0;
tempBoundsT=0;
function
beforeDrawLegendItem( lerh, bounds, icsc )
{
//get the second runtime series
if
( lerh.getDataIndex() == 1){
//Store values first so we can reset
boundsL = bounds.getLeft();
boundsT = bounds.getTop();
boundsH = bounds.getHeight();
boundsW = bounds.getWidth();
bounds.setHeight(0);
bounds.setWidth(0);
lerh.getLabel().setVisible(
false
);
}
//need to move up all the following entries after the hole
if
( lerh.getDataIndex() > 1 ){
tempBoundsT = bounds.getTop();
bounds.setTop(boundsT);
boundsT= tempBoundsT;
}
}
function
afterDrawLegendItem( lerh, bounds, icsc )
{
//Get second runtime series reset changes
if( lerh.getDataIndex() == 1 ){
lerh.getLabel().setVisible(true);
bounds.setHeight(boundsH);
bounds.setWidth(boundsW);
}
}
<br />
Attached example illustrates both cases.