Skip to main content



      Home
Home » Archived » BIRT » Birt Chart Engine Api - set y-axis labels
Birt Chart Engine Api - set y-axis labels [message #1014701] Tue, 26 February 2013 05:05 Go to next message
Eclipse UserFriend
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 18:29 Go to previous message
Eclipse UserFriend
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
Previous Topic:Language of Report Labels
Next Topic:Modify the DataSource in Java
Goto Forum:
  


Current Time: Sat Mar 15 21:07:23 EDT 2025

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

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

Back to the top