Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Birt Chart Engine Api - set y-axis labels
Birt Chart Engine Api - set y-axis labels [message #1014701] Tue, 26 February 2013 10:05 Go to next message
ranjita purwar is currently offline ranjita purwarFriend
Messages: 1
Registered: February 2013
Junior Member
I googled for hours before posting this question here.
I am using Birt's Chart engine Api to generate png files containing charts.
DataSet for x-axis is say, ["A", "B", "C"]
DataSet for y-axis is say, ["1", "2", "3"]

In the chart, instead of displaying the labels on y-axis as 1,2 and 3, I want to instead display "Bad", "Worse", "Worst".
But I can't figure out how can I iterate over the labels of Y-axis and set the captions to a different value. All the solutions I came across so far, talked about using scripts like beforeRender. I haven't worked with the scripts and would like to emphasize that I want to stick with Birt Chart Engine Api.
Can anyone please offer a solution ?
Below is the code into which I would like to embed the solution of the problem.

public void createChart() {
// line charts are based on charts that contain axes
ChartWithAxes chartWithAxes = ChartWithAxesImpl.create();
//chartWithAxes.setTransposed(true);
chartWithAxes.getTitle().setVisible(false);
chartWithAxes.setUnitSpacing(this.unitSpacing);

//customize the plot
Plot p = chartWithAxes.getPlot();
p.getClientArea().setBackground(ColorDefinitionImpl.WHITE());
p.getOutline().setVisible(false);

// customize the legend
Legend lg = chartWithAxes.getLegend();
lg.setVisible(false);

// customize the X-axis
Axis xAxisPrimary = chartWithAxes.getPrimaryBaseAxes()[0];
xAxisPrimary.setType(AxisType.TEXT_LITERAL);
xAxisPrimary.getMajorGrid().getTickAttributes().setVisible(false);
xAxisPrimary.getOrigin().setType(IntersectionType.VALUE_LITERAL);
xAxisPrimary.getLineAttributes().setThickness(2);
if(!getXAxisTitle().isEmpty()){
xAxisPrimary.getTitle().getCaption().setValue(this.getXAxisTitle());
xAxisPrimary.getTitle().setVisible(true);
}
if(!getLabelVisibleXAxis()){
xAxisPrimary.getLabel().setVisible(false);
}
xAxisPrimary.getLabel().getCaption().getFont().setRotation(90);


// customize the Y-axis
Axis yAxisPrimary = chartWithAxes.getPrimaryOrthogonalAxis(xAxisPrimary);
yAxisPrimary.getMajorGrid().getTickAttributes().setVisible(false);
yAxisPrimary.setType(AxisType.LINEAR_LITERAL);
if(!getLabelVisibleYAxis()){
yAxisPrimary.getLabel().setVisible(false);
}
yAxisPrimary.getLineAttributes().setVisible(true);
if(!getYAxisTitle().isEmpty()){
yAxisPrimary.getTitle().getCaption().setValue(this.getYAxisTitle());
yAxisPrimary.getTitle().setVisible(true);
}

// create dataset for X-axis
TextDataSet xAxisValues = TextDataSetImpl.create(getDataXAxis());

// create dataset for Y-axis
NumberDataSet yAxisValues = NumberDataSetImpl.create(getDataYAxis());


// create the base series
Series baseSeries = SeriesImpl.create();
baseSeries.setDataSet(xAxisValues);

// create the orthogonal series
LineSeries orthogonalSeries = (LineSeries) LineSeriesImpl.create();
orthogonalSeries.setDataSet(yAxisValues);
orthogonalSeries.getLineAttributes().setColor(ColorDefinitionImpl.BLACK());

// wrap the base series in the X-axis series definition
SeriesDefinition sdX = SeriesDefinitionImpl.create();
xAxisPrimary.getSeriesDefinitions().add(sdX);
sdX.getSeries().add(baseSeries);


// wrap the orthogonal series in the Y-axis series definition
SeriesDefinition sdY = SeriesDefinitionImpl.create();
yAxisPrimary.getSeriesDefinitions().add(sdY);
sdY.getSeries().add(orthogonalSeries);

createPng(chartWithAxes);
}
Re: Birt Chart Engine Api - set y-axis labels [message #1014966 is a reply to message #1014701] Tue, 26 February 2013 23:29 Go to previous message
Michael Williams is currently offline Michael WilliamsFriend
Messages: 1925
Registered: July 2009
Senior Member

This thread shows how to write a java event handler to overwrite a script method for a chart. This would allow you to override the beforeDrawAxisLabel function and replace the numerical values with your string values.

BIRT Exchange Forums - Chart Java Event Handler


Michael

Developer Evangelist, Silanis
Previous Topic:Language of Report Labels
Next Topic:Modify the DataSource in Java
Goto Forum:
  


Current Time: Sun Jul 15 18:46:47 GMT 2018

Powered by FUDForum. Page generated in 0.01960 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top