Hi,<br />
I am generating birt reports through BIRT API. I want to specify the colors of single series bar chart based on data. I see the below function (beforeDrawDataPoint) that can be used through report design in eclipse to chage the color based on data, but please let me know how can I accomplish the same using BIRT API.<br />
<br />
<br />
function beforeDrawDataPoint(dph, fill, icsc)<br />
{<br />
importPackage( Packages.java.io );<br />
importPackage( Packages.org.eclipse.birt.chart.model.attribute.impl );<br />
<br />
if( dph.getBaseValue() == "Pass" ){<br />
var mycolor = ColorDefinitionImpl.GREEN();<br />
r = mycolor.getRed();<br />
g = mycolor.getGreen();<br />
b = mycolor.getBlue();<br />
fill.set(r, g,

;<br />
} <br />
}<br />
<br />
<br />
My code is below<br />
<br />
<br />
public static Chart createBirtBarAndLineChart(DataSet categoryValues, DataSet[] barSeriesValues, <br />
Object[] barSeriesIdentifier, Object[] lineSeriesDateSet, Object[] lineSeriesIdentifierSet,<br />
String title, String categoryLabel, String valueLabel, <br />
boolean transposed, boolean isPercent, boolean showLegend,<br />
boolean rotateXAxisLabel, Map missionMap) {<br />
<br />
//Create chart instance <br />
ChartWithAxes chart = ChartWithAxesImpl.create();<br />
chart.setType( "Bar Chart" );<br />
chart.setSubType( "Side-by-side" ); <br />
chart.setTransposed(transposed);<br />
chart.setUnitSpacing(30); <br />
//chart.setDimension(ChartDimension.TWO_DIMENSIONAL_WITH_DEPTH_LITERAL);<br />
//Set the chart title <br />
chart.getTitle().getLabel().getCaption().setValue(title);<br />
chart.getTitle().getLabel().getCaption().getFont().setSize(12);<br />
chart.getTitle().getLabel().getCaption().getFont().setName("Arial");<br />
//Set background color<br />
chart.getBlock().setBackground(ColorDefinitionImpl.WHITE());<br />
chart.getPlot().getClientArea().setBackground(ColorDefinitionImpl.WHITE());<br />
chart.getBlock( ).getOutline( ).setVisible( true );<br />
//chart.getBlock( ).setBackground(ColorDefinitionImpl.create(0,0,255));<br />
Legend lg = chart.getLegend( );<br />
<br />
if(showLegend) {<br />
lg.getText( ).getFont().setSize(8);<br />
lg.setPosition( Position.BELOW_LITERAL );<br />
//lg.setAnchor( Anchor.NORTH_LITERAL );<br />
//lg.setDirection(Direction.LEFT_RIGHT_LITERAL);<br />
//lg.setItemType( LegendItemType.CATEGORIES_LITERAL );<br />
}<br />
else {<br />
lg.setVisible(false);<br />
}<br />
<br />
<br />
//Create axes <br />
// X-Axis<br />
Axis xAxisPrimary = ((ChartWithAxes) chart).getPrimaryBaseAxes()[0];<br />
xAxisPrimary.setType( AxisType.TEXT_LITERAL );<br />
if(categoryValues instanceof DateTimeDataSet) {<br />
xAxisPrimary.setFormatSpecifier( JavaDateFormatSpecifierImpl.create( "MMM" ) );<br />
}<br />
<br />
if(categoryLabel != null) {<br />
xAxisPrimary.getTitle().setVisible(true);<br />
xAxisPrimary.getTitle().getCaption().setValue(categoryLabel);<br />
xAxisPrimary.getTitle().getCaption().getFont().setSize(8);<br />
xAxisPrimary.getTitle().getCaption().getFont().setName("Arial");<br />
if(transposed) {<br />
xAxisPrimary.getTitle().getCaption().getFont().setRotation(90);<br />
}<br />
}<br />
xAxisPrimary.getLabel().getCaption().getFont().setSize(8);<br />
xAxisPrimary.getLabel().getCaption().getFont().setName("Arial");<br />
if(rotateXAxisLabel && transposed) {<br />
xAxisPrimary.getLabel().getCaption().getFont().setRotation(90);<br />
}<br />
<br />
if(rotateXAxisLabel) {<br />
xAxisPrimary.getLabel().getCaption().getFont().setRotation(60);<br />
}<br />
//xAxisPrimary.getOrigin( ).setType( IntersectionType.MIN_LITERAL );<br />
<br />
<br />
// Y-Axis<br />
Axis yAxisPrimary = chart.getPrimaryOrthogonalAxis( xAxisPrimary );<br />
yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );<br />
yAxisPrimary.setType( AxisType.LINEAR_LITERAL );<br />
yAxisPrimary.getOrigin().setType(IntersectionType.VALUE_LITERAL);<br />
yAxisPrimary.getOrigin().setValue(NumberDataElementImpl.create(0));<br />
yAxisPrimary.setGapWidth(30);<br />
yAxisPrimary.getLabel().getCaption().getFont().setSize(8);<br />
yAxisPrimary.getLabel().getCaption().getFont().setName("Arial");<br />
<br />
if(valueLabel != null) {<br />
yAxisPrimary.getTitle().setVisible(true);<br />
yAxisPrimary.getTitle().getCaption().setValue(valueLabel);<br />
yAxisPrimary.getTitle().getCaption().getFont().setSize(8);<br />
yAxisPrimary.getTitle().getCaption().getFont().setName("Arial");<br />
<br />
}<br />
if(transposed) {<br />
yAxisPrimary.getOrigin().setType(IntersectionType.MAX_LITERAL);<br />
yAxisPrimary.setLabelPosition(Position.RIGHT_LITERAL);<br />
//yAxisPrimary.getLabel().setVisible(false);<br />
}<br />
<br />
yAxisPrimary.setPercent(isPercent);<br />
//Create the X series <br />
<br />
Series seCategory = SeriesImpl.create();<br />
seCategory.setDataSet(categoryValues);<br />
<br />
SeriesDefinition sdX = SeriesDefinitionImpl.create( );<br />
sdX.getSeriesPalette( ).shift( 0 );<br />
xAxisPrimary.getSeriesDefinitions().add(sdX);<br />
sdX.getSeries( ).add( seCategory );<br />
<br />
//Create the Y series <br />
<br />
SeriesDefinition sdY = SeriesDefinitionImpl.create();<br />
<br />
Palette palette = sdY.getSeriesPalette();<br />
palette.shift( -3 );<br />
<br />
<br />
Iterator iter = palette.getEntries().iterator();<br />
int index = 0;<br />
<br />
while(iter.hasNext()) {<br />
ColorDefinitionImpl fill = (ColorDefinitionImpl)iter.next();<br />
<br />
if(index == 0) {<br />
//fill.set(0, 128, 255); // blue green<br />
if(barSeriesValues.length > 1){<br />
fill.set(0, 0, 240);<br />
}else{<br />
fill.set(210, 0, 0);<br />
}<br />
//fill.set(210, 0, 0);<br />
<br />
}<br />
else if(index == 1) {<br />
//fill.set(0, 0, 255); // blue<br />
if(barSeriesValues.length > 1){<br />
fill.set(210, 0, 0);<br />
}else{<br />
fill.set(0, 0, 240);<br />
}<br />
index++;<br />
}<br />
else if(index == 2) {<br />
//fill.set(0, 128, 128); // darker blue green<br />
fill.set(0, 154,0);<br />
index++;<br />
}<br />
else { // <br />
break;<br />
}<br />
} <br />
<br />
<br />
<br />
yAxisPrimary.getSeriesDefinitions().add(sdY);<br />
<br />
//sdY.getSeriesPalette().update(ColorDefinitionImpl.create(0,0,255));<br />
<br />
for(int i=0; i<barSeriesValues.length; i++) {<br />
DataSet valuesDataSet = barSeriesValues
;<br />
BarSeries bs = (BarSeries) BarSeriesImpl.create();<br />
bs.setDataSet(valuesDataSet);<br />
bs.getLabel().getCaption().getFont().setSize( 8 );<br />
bs.getLabel().getCaption().getFont().setName("Arial");<br />
if(barSeriesIdentifier != null) {<br />
bs.setSeriesIdentifier( barSeriesIdentifier );<br />
}<br />
sdY.getSeries().add(bs);<br />
}<br />
for(int i=0; i<lineSeriesDateSet.length; i++) {<br />
DataSet[] dataSet = (DataSet[])lineSeriesDateSet;<br />
Object[] lineSeriesIdentifier = (Object[])lineSeriesIdentifierSet;<br />
for(int j=0; j<dataSet.length; j++) {<br />
DataSet valuesDataSet = dataSet[j];<br />
LineSeries ls = (LineSeries) LineSeriesImpl.create( );<br />
ls.setDataSet( valuesDataSet );<br />
ls.getLabel().getCaption().getFont().setSize( 8 );<br />
ls.getLabel().getCaption().getFont().setName("Arial");<br />
ls.setCurve( true );<br />
if(lineSeriesIdentifier != null) {<br />
ls.setSeriesIdentifier( lineSeriesIdentifier[j] );<br />
}<br />
sdY.getSeries().add(ls);<br />
}<br />
}<br />
<br />
return chart;<br />
}<br />
<br />
Please help me in solving this. I've been trying to solve this for 3days.<br />
<br />
Thanks.