Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Adding hyperlink to titles and label
emlddgs
Hi,
As a newbie I wanted to know how to progamatically add interactivity to a chart. If you see below I have a sidebyside bar chart, but I want to add hyperlinks to the title and datapoints within the chart. Is there an easy way to do this?
private Chart createSideBySideBar(CommonReportSection reportSection )
{
SeriesDefinition series = null;
List<CommonInterfaceDataSeries> dataSerieses = reportSection.DataSerieses;
String name = reportSection.Name;
Series seCategory = null;
Query [] qu;
qu = new Query [(dataSerieses.size())];
BarSeries[] bs = new BarSeries [(dataSerieses.size())];
ChartWithAxes cwaBar = ChartWithAxesImpl.create( );
cwaBar.setType( "Bar Chart" );
cwaBar.setSubType( "Side-by-side" ); //$NON-NLS-1$
// Plot
cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
cwaBar.getBlock( ).getOutline( ).setVisible( true );
Plot p = cwaBar.getPlot( );
p.getClientArea( ).setBackground( ColorDefinitionImpl.create( 255,
255,
225 ) );
// Title
cwaBar.getTitle( )
.getLabel( )
.getCaption( )
.setValue( reportSection.Name ); //$NON-NLS-1$
cwaBar.getBlock().setBounds(BoundsImpl.create(0, 0, 252, 288));
// Legend
Legend lg = cwaBar.getLegend( );
lg.setItemType( LegendItemType.SERIES_LITERAL );
final Fill[] fiaOrth = {
ColorDefinitionImpl.BLACK( ),
ColorDefinitionImpl.RED( ),
ColorDefinitionImpl.BLUE(),
ColorDefinitionImpl.CYAN(),
ColorDefinitionImpl.GREEN(),
ColorDefinitionImpl.GREY(),
ColorDefinitionImpl.ORANGE(),
ColorDefinitionImpl.PINK(),
ColorDefinitionImpl.WHITE(),
ColorDefinitionImpl.YELLOW()
};
// X-Axis
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
xAxisPrimary.setType( AxisType.TEXT_LITERAL );
xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );
xAxisPrimary.getOrigin( ).setType( IntersectionType.MIN_LITERAL );
xAxisPrimary.getTitle().getCaption().setValue((dataSerieses.get(0).Title));
xAxisPrimary.
xAxisPrimary.getTitle().setVisible(true);
// Y-Axis
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
yAxisPrimary.getLabel( ).getCaption( ).getFont( ).setRotation( 90 );
//yAxisPrimary.getLabel().getCaption().setValue((dataSerieses.get(1).Title));
//yAxisPrimary.getLabel().setVisible( true );
yAxisPrimary.getTitle().getCaption().setValue((dataSerieses.get(1).Title));
yAxisPrimary.getTitle().setVisible(true);
SampleData sd = DataFactory.eINSTANCE.createSampleData( );
BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData( );
sdBase.setDataSetRepresentation( "" );//$NON-NLS-1$
sd.getBaseSampleData( ).add( sdBase );
OrthogonalSampleData sdOrthogonal1 = DataFactory.eINSTANCE.createOrthogonalSampleData( );
sdOrthogonal1.setDataSetRepresentation( "" );//$NON-NLS-1$
sdOrthogonal1.setSeriesDefinitionIndex( 0 );
sd.getOrthogonalSampleData( ).add( sdOrthogonal1 );
OrthogonalSampleData sdOrthogonal2 = DataFactory.eINSTANCE.createOrthogonalSampleData( );
sdOrthogonal2.setDataSetRepresentation( "" );//$NON-NLS-1$
sdOrthogonal2.setSeriesDefinitionIndex( 1 );
sd.getOrthogonalSampleData( ).add( sdOrthogonal2 );
cwaBar.setSampleData( sd );
for (int j = 0; j < dataSerieses.size(); j++)
{
// X-Series
if (dataSerieses.get(j).AxisNumber == 0){
StringBuffer exp = new StringBuffer();
exp.append("row[\"Series").append(j).append("\"]");
seCategory = SeriesImpl.create();
qu[j] = QueryImpl.create(exp.toString());
seCategory.getDataDefinition().add(qu[j]);
series = SeriesDefinitionImpl.create();
xAxisPrimary.getSeriesDefinitions( ).add( series );
series.getSeries().add( seCategory );
}
// Y Series
if (dataSerieses.get(j).AxisNumber != 0){
StringBuffer exp = new StringBuffer();
exp.append("row[\"Series").append(j).append("\"]");
bs[j] = (BarSeries) BarSeriesImpl.create();
bs[j].setSeriesIdentifier(dataSerieses.get(j).Title);
qu[j] = QueryImpl.create(exp.toString());
bs[j].getDataDefinition().add(qu[j]);
bs[j].getLabel( ).setVisible( true );
bs[j].setLabelPosition( Position.INSIDE_LITERAL );
SeriesDefinition sdY = SeriesDefinitionImpl.create( );
sdY.getSeriesPalette( ).shift( -2 );
sdY.getSeriesPalette( ).getEntries( ).clear( );
sdY.getSeriesPalette( ).getEntries( ).add( fiaOrth[j] );
yAxisPrimary.getSeriesDefinitions( ).add( sdY );
sdY.getSeries( ).add( bs[j] );
}
}
return cwaBar
}
Find more posts tagged with
Comments
emlddgs
I found a solution, but it was not what I hoped. in previous articles and discussions, e.g. FAQ it is simply doing the following:
PieSeries sePie = ...;
sePie.getTriggers().add(
TriggerImpl.create(
TriggerCondition.MOUSE_CLICK_LITERAL,
ActionImpl.create(
ActionType.URL_REDIRECT_LITERAL,
URLValueImpl.create(
"
http://www.actuate.com"
, null, "city", "population", null
)
)
)
);
If you are using the BIRT chart engine and you are generating a report design file to use in the birt viewer, this solution will fail with 404 error when you try and select the hyperlink. If you look at the link in the designer it throws an exception essentially saying malformed link.
This is because the designer appears to generate a javascript statement for the hyperlink and it is parsed accordingly, so if you are generating a design file from java source you will need something allong the lines of the following for the hyperlink to work in BIRT viewer:
String url = ""
+ "<structure name=\"action\">"
+ "<property name=\"linkType\">hyperlink</property>"
+ "<expression name=\"uri\" type=\"constant\">
http://www.o2.co.uk</expression>"
;
+ "<property name=\"targetWindow\">_self</property>"
+ "</structure>";
URLValue uv = URLValueImpl.create(url,"", "", "", "");
// Add a title and place a hyperlink on the title
cwaLine.getTitle( )
.getLabel( )
.getCaption( )
.setValue( reportSection.Name );
cwaLine.getTitle().getTriggers().add(TriggerImpl.create(
TriggerCondition.ONCLICK_LITERAL,
ActionImpl.create(ActionType.URL_REDIRECT_LITERAL,
uv)));
With this solution it is possible to place a hyperlink on almost anything, titles, data series, data points.