站内搜索

返回   安讯中国 > 安讯产品 > 百灵报表(BIRT)
注册
忘记密码?
论坛帮助 日历事件 搜索 今日新帖 标记版面已读

回复
 
LinkBack 主题工具 搜索本主题 显示模式
  #1 (permalink)  
旧 2008-7-21, 05:20 PM
Junior Member
 
注册日期: 2008-6-20
帖子: 25
存款: 183
默认 求助:如何给图表增加事件响应

效果如下图:
如何实现:当然我把鼠标放到某个柱状条上,可以弹出一个信息框,显示该柱状图的数值。比如当我我把鼠标移到粉红条上时,可以显示弹出一个框,显示出25来。其实就是想知道如何为图表增加事件响应。以下是一个例子的代码:
public static final Chart createBar( )
{
ChartWithAxes cwaBar = ChartWithAxesImpl.create( );
cwaBar.setType( "Bar Chart" );
cwaBar.setSubType( "Side-by-side" ); //$NON-NLS-1$
cwaBar.setUnitSpacing(80);
// 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( "Side-by-side Bar Chart" ); //$NON-NLS-1$

// Legend
Legend lg = cwaBar.getLegend( );
// cwaBar.getLegend( ).setVisible( false );
lg.setItemType( LegendItemType.CATEGORIES_LITERAL );
System.out.println("int--->"+lg.getColumn());

// X-Axis
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];

// xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );
// xAxisPrimary.getScale( ).setMin( DateTimeDataElementImpl.create( new CDateTime(2008,1,1) ) );
// xAxisPrimary.getScale( ).setMax( DateTimeDataElementImpl.create( new CDateTime(2009,1,1) ) );
xAxisPrimary.setFormatSpecifier( JavaDateFormatSpecifierImpl.create( "MM/dd/yyyy" ) );//$NON-NLS-1$
xAxisPrimary.setType( AxisType.DATE_TIME_LITERAL );
// xAxisPrimary.getScale().setUnit(ScaleUnitType.DAYS_LITERAL);
// xAxisPrimary.getScale().setStepNumber(1);
xAxisPrimary.getOrigin( ).setType( IntersectionType.MIN_LITERAL );


xAxisPrimary.getLabel( )
.getCaption( )
.setColor( ColorDefinitionImpl.RED( ) );
xAxisPrimary.getLabel( ).getCaption( ).getFont( ).setRotation( -30 );
xAxisPrimary.getLabel().setVisible(true);


// Y-Axis
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
xAxisPrimary.getMajorGrid( ).getLineAttributes( ).setVisible( true );
yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
yAxisPrimary.getLabel( ).getCaption( ).getFont( ).setRotation( 90 );

yAxisPrimary.getMarkerRanges( )
.add( MarkerRangeImpl.create( yAxisPrimary,
NumberDataElementImpl.create( 20 ),
// org.eclipse.birt.chart.model.data.impl.TextDataSetImpl
NumberDataElementImpl.create( 28 ),
ColorDefinitionImpl.GREEN( ).translucent( ) ) );

// Data Set
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// TextDataSet categoryValues = TextDataSetImpl.create( new String[]{
// sdf.parse("2008-02-05"), "2008-02-07", "2008-04-05", "2008-04-05", "2008-07-05"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$

DateTimeDataSet categoryValues = DateTimeDataSetImpl.create( new Calendar[]{
new CDateTime( 2008, 1, 21 ),
new CDateTime( 2008, 1, 20 ),
new CDateTime( 2008, 1, 17 ),
new CDateTime( 2008, 1, 16 ),
new CDateTime( 2008, 3, 15 )
} );

NumberDataSet orthoValues1 = NumberDataSetImpl.create( new double[]{
25, 35, 15, 5, 20
} );
NumberDataSet orthoValues2 = NumberDataSetImpl.create( new double[]{
5, 10, 25, 10, 5
} );


// X-Series
Series seCategory = SeriesImpl.create( );
seCategory.setDataSet( categoryValues );


SeriesDefinition sdX = SeriesDefinitionImpl.create( );
sdX.getSeriesPalette( ).shift( -1 );
xAxisPrimary.getSeriesDefinitions( ).add( sdX );
sdX.getSeries( ).add( seCategory );


// Y-Series
BarSeries bs1 = (BarSeries) BarSeriesImpl.create( );
bs1.setDataSet( orthoValues1 );
// bs1.getLabel( ).setVisible( true );
// bs1.setLabelPosition( Position.INSIDE_LITERAL );
bs1.setTranslucent( true );
bs1.setLabelPosition( Position.INSIDE_LITERAL );

// BarSeries bs2 = (BarSeries) BarSeriesImpl.create( );
// bs2.setDataSet( orthoValues2 );
// bs2.getLabel( ).setVisible( true );
// bs2.setLabelPosition( Position.INSIDE_LITERAL );

SeriesDefinition sdY = SeriesDefinitionImpl.create( );
yAxisPrimary.getSeriesDefinitions( ).add( sdY );
sdY.getSeries( ).add( bs1 );
// sdY.getSeries( ).add( bs2 );

return cwaBar;
}
能否帮我修改此例,实现一下当然我把鼠标放到某个柱状条上,可以弹出一个信息框,显示该柱状图的数值的功能。万分感谢!!!
上传的图像
文件类型: jpg legend.JPG (80.9 KB, 9 次查看)
回复时引用此帖
  #2 (permalink)  
旧 2008-7-21, 05:29 PM
Junior Member
 
注册日期: 2008-6-16
帖子: 9
存款: 155
默认

用report designer直接做吧, chart builder里有相应的选项. 新接触birt的话, 还是用report designer比较好, 等熟练了再学习用api实现.
回复时引用此帖
  #3 (permalink)  
旧 2008-7-21, 06:02 PM
Junior Member
 
注册日期: 2008-6-20
帖子: 25
存款: 183
默认

其实我也想用来着,不过我们由于我是要把报表集成到一个RCP的应用里面,直接用API生成,集成的时候方便。
回复时引用此帖
  #4 (permalink)  
旧 2008-7-22, 10:44 AM
Moderator
 
注册日期: 2008-5-30
帖子: 79
存款: 865
默认

你试一下在bs1上加上如下事件:
bs1.getTriggers( ).add(
TriggerImpl.create(
TriggerCondition.ONMOUSEMOVE_LITERAL,
ActionImpl.create(
ActionType.SHOW_TOOLTIP_LITERAL,
TooltipValueImpl.create( 500, null ) ) ) );
回复时引用此帖
  #5 (permalink)  
旧 2008-7-22, 02:14 PM
Junior Member
 
注册日期: 2008-6-20
帖子: 25
存款: 183
默认

引用:
作者: Maggie Shen 查看帖子
你试一下在bs1上加上如下事件:
bs1.getTriggers( ).add(
TriggerImpl.create(
TriggerCondition.ONMOUSEMOVE_LITERAL,
ActionImpl.create(
ActionType.SHOW_TOOLTIP_LITERAL,
TooltipValueImpl.create( 500, null ) ) ) );
我加了这段代码,但是显示的时候还是没有效果???。不知道是哪里出了问题。另外我导入了
import org.eclipse.birt.chart.model.data.impl.ActionImpl;
这个包。
回复时引用此帖
  #6 (permalink)  
旧 2008-7-22, 05:42 PM
Moderator
 
注册日期: 2008-5-30
帖子: 79
存款: 865
默认

这段代码我试过,应该是工作的。所以问题可能出在输出的部分。建议使用svg输出试一下。我贴了一个svg输出的例子,供参考。下载后,将后缀名改为java应该就可以运行了。
上传的附件
文件类型: txt Regression_117876_svg.txt (16.2 KB, 4 次查看)
回复时引用此帖
  #7 (permalink)  
旧 2008-7-23, 10:16 AM
Junior Member
 
注册日期: 2008-6-20
帖子: 25
存款: 183
默认

万分感谢,不过运行程序的时候报错。
2008-7-23 10:12:10 org.eclipse.birt.chart.util.PluginSettings instance
警告: Exception
org.eclipse.birt.core.exception.BirtException: Cant startup the OSGI framework
at org.eclipse.birt.core.framework.Platform.startup(Platform.java:91)
at org.eclipse.birt.chart.util.PluginSettings.instance(PluginSettings.java:338)
at org.eclipse.birt.chart.util.PluginSettings.instance(PluginSettings.java:314)
at birt.Regression_117876_svg.<init>(Regression_117876_svg.java:103)
at birt.Regression_117876_svg.main(Regression_117876_svg.java:118)
Caused by: org.eclipse.birt.core.exception.BirtException: Could not find the Framework - org.eclipse.osgi
at org.eclipse.birt.core.framework.osgi.OSGILauncher.startup(OSGILauncher.java:95)
at org.eclipse.birt.core.framework.Platform.startup(Platform.java:79)
... 4 more
我现在正在下package org.eclipse.birt.report.test的源码,看看。想问下这个包是干嘛用的。谢谢
回复时引用此帖
  #8 (permalink)  
旧 2008-7-23, 11:48 AM
Moderator
 
注册日期: 2008-5-30
帖子: 79
存款: 865
默认

这个错误应该不会影响到运行结果。如果想消除这个错误,可以在启动应用的时候,把BIRT_HOME作为VM参数传递,例如 -DBIRT_HOME="C:\birt-runtime-2_3_0\ReportEngine"。

report.test这个包是测试用的。
回复时引用此帖
  #9 (permalink)  
旧 2008-7-23, 04:16 PM
Junior Member
 
注册日期: 2008-6-20
帖子: 25
存款: 183
默认

我现在知道为什么加了事件以后响应不了。可能和我显示报表的方式有关:
第一种显示方法:(参见:org.eclipse.birt.chart.examples/src/org/eclipse/birt/chart/examples/view/util/ChartPreview.java)
public void renderModel( Chart cm )
{
// if ( cm == null )
// {
// return;
// }
this.cm = cm;

if ( preview != null && !preview.isDisposed( ) )
{
updateBuffer( );
preview.redraw( );
}
}

/**
* Generate and render the chart model,the chart image is stored in a
* buffer. The buffer will be updated only when the chart model is changed.
*/
private void updateBuffer( )
{
if ( bIsPainting )
{
return;
}
Throwable paintError = null;

Rectangle re = preview.getClientArea( );
final Rectangle adjustedRe = new Rectangle( 0, 0, re.width, re.height );

if ( adjustedRe.width - 2 * X_OFFSET <= 0
|| adjustedRe.height - 2 * Y_OFFSET <= 0 )
{
if ( buffer != null && !buffer.isDisposed( ) )
{
buffer.dispose( );
buffer = null;
}
return;
}

if ( cm == null )
{
buffer = null;
}
else
{
bIsPainting = true;
Image oldBuffer = null;
if ( buffer == null )
{
buffer = new Image( Display.getDefault( ), adjustedRe );
}
else
{
Rectangle ore = buffer.getBounds( );

oldBuffer = buffer;

if ( !adjustedRe.equals( ore ) )
{
buffer = new Image( Display.getDefault( ), adjustedRe );
}
}

GC gc = new GC( buffer );

// fill default backgournd as white.
gc.setForeground( Display.getDefault( )
.getSystemColor( SWT.COLOR_WHITE ) );
gc.fillRectangle( buffer.getBounds( ) );

final Bounds bo = BoundsImpl.create( X_OFFSET,
Y_OFFSET,
adjustedRe.width - 2 * X_OFFSET,
adjustedRe.height - 2 * Y_OFFSET );

IDeviceRenderer deviceRenderer = null;
try
{
deviceRenderer = PluginSettings.instance( )
.getDevice( "dv.SWT" ); //$NON-NLS-1$
deviceRenderer.setProperty( IDeviceRenderer.GRAPHICS_CONTEXT,
gc );
bo.scale( 72d / deviceRenderer.getDisplayServer( )
.getDpiResolution( ) ); // CONVERT
// TO
// POINTS

// GENERATE AND RENDER THE CHART
final Generator gr = Generator.instance( );
RunTimeContext rtc = new RunTimeContext( );

GeneratedChartState state = gr.build( deviceRenderer.getDisplayServer( ),
cm,
bo,
null,
rtc,
null );

gr.render( deviceRenderer, state );
}
catch ( Exception ex )
{
paintError = ex;
}
finally
{
gc.dispose( );
if ( deviceRenderer != null )
{
deviceRenderer.dispose( );
}
}

if ( paintError != null )
{
buffer = oldBuffer;
}
if ( oldBuffer != null && oldBuffer != buffer )
{
oldBuffer.dispose( );
}
bIsPainting = false;
}

}
然后我在我的SWT程序里用如下调用:
paintCanvas = new Canvas( parent, SWT.BORDER );
paintCanvas.setLayoutData( new GridData( GridData.FILL_BOTH ) );
paintCanvas.setBackground( Display.getDefault( )
.getSystemColor( SWT.COLOR_WHITE ) );
preview = new ChartPreview( );
paintCanvas.addPaintListener( preview );
paintCanvas.addControlListener( preview );
preview.setPreview( paintCanvas );
preview.renderModel(createBar( )); //createBar( )我要调的图表。用这种方法不能正确显示加了事件的代码。
第二种显示图表的方法:(参见:org.eclipse.birt.chart.examples.api.interactivity.SwtInteractivityViewer)
private IDeviceRenderer idr = null;
public final void paintControl( PaintEvent e )
{
idr = ps.getDevice( "dv.SWT" );//$NON-NLS-1$
idr.setProperty(IDeviceRenderer.UPDATE_NOTIFIER, this );
Rectangle d = this.getClientArea( );
Image imgChart = new Image( this.getDisplay( ), d );
GC gcImage = new GC( imgChart );
idr.setProperty( IDeviceRenderer.GRAPHICS_CONTEXT, gcImage );

Bounds bo = BoundsImpl.create( 0, 0, d.width, d.height );
bo.scale( 72d / idr.getDisplayServer( ).getDpiResolution( ) );

Generator gr = Generator.instance( );
if ( bNeedsGeneration )
{
bNeedsGeneration = false;
try
{
gcs = gr.build( idr.getDisplayServer( ),
cm,
bo,
null,
null,
null );
}
catch ( ChartException ce )
{
ce.printStackTrace( );
}
}

try
{
gr.render( idr, gcs );
GC gc = e.gc;
gc.drawImage( imgChart, d.x, d.y );
}
catch ( ChartException gex )
{
showException( e.gc, gex );
}
}
用这种方法可以正确显示图表响应的事件。

现在不明白的是这二种方法显示有何区别。他们分别适用于什么地方。(以上是官方例子里的显示方法)。
回复时引用此帖
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

论坛启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码
Trackbacks are 启用
Pingbacks are 启用
Refbacks are 启用


服务条款 | 隐私政策
安讯中国 上海浦东新区浦东南路1271号华融大厦21层2101室
电话:(+86)21-58826388   发送邮件联系我们  沪ICP备06010344号
Actuate Corporation © 2008
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

Content Relevant URLs by vBSEO 3.1.0