Add % sign to Y-series values
Hi,<br />
I want to add "%" sign to Y-axis values. Below is the code that I am using to generate the chart. I tried<br />
yAxisPrimary.setPercent(isPercent);..but still it is not showing the "%".I want like 10%. Please let me know how can I do it.<br />
<br />
<br />
<br />
<br />
public static Chart createBirtBarChart(DataSet categoryValues, DataSet[] seriesValues, Object[] seriesIdentifier,String title, String categoryLabel, String valueLabel, boolean transposed, boolean isPercent, boolean showLegend,<br />
boolean rotateXAxisLabel) {<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.create( 255,<br />
255,<br />
225 ));<br />
chart.getBlock( ).getOutline( ).setVisible( true );<br />
//chart.getBlock( ).setBackground(ColorDefinitionImpl.create(0,0,255));<br />
Legend lg = chart.getLegend( );<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"+" "+"YY" ) );<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 />
//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.setPercent(isPercent);<br />
<br />
if (isPercent)<br />
yAxisPrimary.setInterval(2);<br />
<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.getLabel().getCaption().getFont().setSize(8);<br />
yAxisPrimary.getLabel().getCaption().getFont().setName("Arial");<br />
<br />
<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 />
Palette palette = sdY.getSeriesPalette( );<br />
palette.shift( -3 );<br />
Iterator iter = palette.getEntries().iterator();<br />
int index = 0;<br />
<br />
while(iter.hasNext()) {<br />
ColorDefinitionImpl fill = (ColorDefinitionImpl)iter.next();<br />
if(index == 0) {<br />
fill.set(0, 128, 255); // blue green<br />
index++;<br />
}<br />
else if(index == 1) {<br />
fill.set(0, 0, 255); // blue<br />
index++;<br />
}<br />
else if(index == 2) {<br />
fill.set(0, 128, 128); // darker blue green<br />
index++;<br />
}<br />
else { // <br />
break;<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<seriesValues.length; i++) {<br />
DataSet valuesDataSet = seriesValues;<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 />
sdY.getSeries().add(bs);<br />
if(seriesIdentifier != null) {<br />
bs.setSeriesIdentifier( seriesIdentifier );<br />
}<br />
}<br />
<br />
return chart;<br />
}<br />
<br />
<br />
Thanks,<br />
Susmitha.