Home » Archived » BIRT » Pass parameters to java script event handlers in charts (ChartEngine)
Pass parameters to java script event handlers in charts (ChartEngine) [message #259944] |
Tue, 30 October 2007 09:43  |
Eclipse User |
|
|
|
Originally posted by: erdal.karaca.airbus.com
Hi,
I need to know whether it is possible to pass some arguments to a script
event handler for a given chart object:
Chart chart = ... any chart object
chart.setScript( HistogramEventCallback.class.getName() );
Setting the script for this chart this way makes it impossible to pass
arguments to the executed HistogramEventCallback object without using any
static (class) transfer attributes.
Is there an elegant solution to this problem?
I could write:
//----
class ChartGenerator {
static Map< String, Object > chartProps = new HashMap< String, Object >();
Chart createChart() {
chartProps.put( "data-point-labels", new ArrayList< String >() );
Chart chart = ... any chart object
chart.setScript( HistogramEventCallback.class.getName() );
// go on initializing the chart...
}
}
class HistogramEventCallback extends ChartEventHandlerAdapter {
public void beforeDrawDataPointLabel( DataPointHints dph, Label label,
IChartScriptContext icsc ) {
if ( ((List)ChartGenerator.chartProps.get( "data-point-labels"
)).isEmpy() ) {
// do something...
}
}
}
As I mentioned this is not elegant, since you have to deal with object
synchronisation etc.
Thanks!
|
|
|
Re: Pass parameters to java script event handlers in charts (ChartEngine) [message #259947 is a reply to message #259944] |
Tue, 30 October 2007 09:50   |
Eclipse User |
|
|
|
Hi,
What kind of arguments do you need to pass? Each event function let you
access the IChartScriptContext, which gives you full access to the chart
model. (context.getChartInstance()).
More generally you can create an application context (IExternalContext) and
pass it in the build or prepare method when generating the chart. This will
then be available through IChartScriptContext.getExternalContext(). This can
be used to pass runtime information to the event handler (for instance in a
web app, you could pass session variables).
Thanks,
David
"Erdal Karaca" <erdal.karaca@airbus.com> wrote in message
news:861691e1514e420fbf2ec93f818e664a$1@www.eclipse.org...
> Hi,
>
> I need to know whether it is possible to pass some arguments to a script
> event handler for a given chart object:
>
> Chart chart = ... any chart object
> chart.setScript( HistogramEventCallback.class.getName() );
>
> Setting the script for this chart this way makes it impossible to pass
> arguments to the executed HistogramEventCallback object without using any
> static (class) transfer attributes.
>
> Is there an elegant solution to this problem?
>
> I could write:
>
> //----
> class ChartGenerator {
>
> static Map< String, Object > chartProps = new HashMap< String, Object >();
>
> Chart createChart() {
> chartProps.put( "data-point-labels", new ArrayList< String >() );
> Chart chart = ... any chart object
> chart.setScript( HistogramEventCallback.class.getName() );
> // go on initializing the chart...
> }
> }
>
> class HistogramEventCallback extends ChartEventHandlerAdapter {
> public void beforeDrawDataPointLabel( DataPointHints dph, Label label,
> IChartScriptContext icsc ) {
> if ( ((List)ChartGenerator.chartProps.get(
> "data-point-labels" )).isEmpy() ) {
> // do something...
> }
> }
> }
>
>
> As I mentioned this is not elegant, since you have to deal with object
> synchronisation etc.
>
> Thanks!
>
|
|
|
How to pass cutom parameters to java script handler while defining a chart model [message #260016 is a reply to message #259947] |
Wed, 31 October 2007 02:43   |
Eclipse User |
|
|
|
Originally posted by: erdal.karaca.airbus.com
Thanks!
Unfortunately, I need to pass custom parameters to the chart while
defining the model (i.e. series values, appearance etc.). Building or
rendering the chart is done elsewhere. Hence, it is too late to pass
arguments to the chart object when it is being built or rendered. I would
have to modify the application's architecture to support this ;-(
Maybe one can (mis)use a series' identifier to pass custom parameters
while defining the chart model (Series.setSeriesIdentifier( Object )
expects an object as parameter, so one could pass a Map, or the like). Of
course, this is not elegant as your suggestion...
The following is ugly code but it works:
//---
// while defining your chart model...
//---
Series paramSeries = SeriesImpl.create();
Map< String, Object > props = new HashMap< String, Object >();
props.put( "stddev", new Double( 0.004 ) );
paramSeries.setSeriesIdentifier( props );
sdX.getSeries().add( paramSeries );
//---
//in your script handler...
//---
public void beforeDrawDataPointLabel( DataPointHints dph, Label label,
IChartScriptContext icsc ) {
ChartWithAxes chart = (ChartWithAxes) icsc.getChartInstance();
Axis xAxis = chart.getPrimaryBaseAxes()[ 0 ];
SeriesDefinition sdx =
(SeriesDefinition) xAxis.getSeriesDefinitions().get( 0 );
Series propsSeries = (Series) sdx.getSeries().get( sdx.getSeries().size()
- 1 );
Map< String, Object > props = (Map< String, Object >)
propsSeries.getSeriesIdentifier();
System.out.println( props.get( "stddev" ) );
}
David Michonneau wrote:
> Hi,
> What kind of arguments do you need to pass? Each event function let you
> access the IChartScriptContext, which gives you full access to the chart
> model. (context.getChartInstance()).
> More generally you can create an application context (IExternalContext) and
> pass it in the build or prepare method when generating the chart. This will
> then be available through IChartScriptContext.getExternalContext(). This can
> be used to pass runtime information to the event handler (for instance in a
> web app, you could pass session variables).
> Thanks,
> David
> "Erdal Karaca" <erdal.karaca@airbus.com> wrote in message
> news:861691e1514e420fbf2ec93f818e664a$1@www.eclipse.org...
>> Hi,
>>
>> I need to know whether it is possible to pass some arguments to a script
>> event handler for a given chart object:
>>
>> Chart chart = ... any chart object
>> chart.setScript( HistogramEventCallback.class.getName() );
>>
>> Setting the script for this chart this way makes it impossible to pass
>> arguments to the executed HistogramEventCallback object without using any
>> static (class) transfer attributes.
>>
>> Is there an elegant solution to this problem?
>>
>> I could write:
>>
>> //----
>> class ChartGenerator {
>>
>> static Map< String, Object > chartProps = new HashMap< String, Object >();
>>
>> Chart createChart() {
>> chartProps.put( "data-point-labels", new ArrayList< String >() );
>> Chart chart = ... any chart object
>> chart.setScript( HistogramEventCallback.class.getName() );
>> // go on initializing the chart...
>> }
>> }
>>
>> class HistogramEventCallback extends ChartEventHandlerAdapter {
>> public void beforeDrawDataPointLabel( DataPointHints dph, Label label,
>> IChartScriptContext icsc ) {
>> if ( ((List)ChartGenerator.chartProps.get(
>> "data-point-labels" )).isEmpy() ) {
>> // do something...
>> }
>> }
>> }
>>
>>
>> As I mentioned this is not elegant, since you have to deal with object
>> synchronisation etc.
>>
>> Thanks!
>>
|
|
|
Re: How to pass cutom parameters to java script handler while defining a chart model [message #260034 is a reply to message #260016] |
Wed, 31 October 2007 05:30   |
Eclipse User |
|
|
|
I think the way you do it is not really supported and might get broken with
a future BIRT update. Also if you plan to save your chart model to disk at
any time, it will not save this data.
I am not sure why you cannot create a wrapper object containing the chart
model + your parameters. That shouldn't really affect your application
architecture?
Thanks,
David
"Erdal Karaca" <erdal.karaca@airbus.com> wrote in message
news:71ee971dd4f84abd6687e05d42528bbb$1@www.eclipse.org...
> Thanks!
>
> Unfortunately, I need to pass custom parameters to the chart while
> defining the model (i.e. series values, appearance etc.). Building or
> rendering the chart is done elsewhere. Hence, it is too late to pass
> arguments to the chart object when it is being built or rendered. I would
> have to modify the application's architecture to support this ;-(
>
> Maybe one can (mis)use a series' identifier to pass custom parameters
> while defining the chart model (Series.setSeriesIdentifier( Object )
> expects an object as parameter, so one could pass a Map, or the like). Of
> course, this is not elegant as your suggestion...
>
> The following is ugly code but it works:
>
> //---
> // while defining your chart model...
> //---
> Series paramSeries = SeriesImpl.create();
> Map< String, Object > props = new HashMap< String, Object >();
> props.put( "stddev", new Double( 0.004 ) );
> paramSeries.setSeriesIdentifier( props );
> sdX.getSeries().add( paramSeries );
>
> //---
> //in your script handler...
> //---
> public void beforeDrawDataPointLabel( DataPointHints dph, Label label,
> IChartScriptContext icsc ) {
> ChartWithAxes chart = (ChartWithAxes) icsc.getChartInstance();
>
> Axis xAxis = chart.getPrimaryBaseAxes()[ 0 ];
> SeriesDefinition sdx =
> (SeriesDefinition) xAxis.getSeriesDefinitions().get( 0 );
>
> Series propsSeries = (Series) sdx.getSeries().get(
> sdx.getSeries().size() - 1 );
> Map< String, Object > props = (Map< String, Object >)
> propsSeries.getSeriesIdentifier();
>
> System.out.println( props.get( "stddev" ) );
> }
>
> David Michonneau wrote:
>
>> Hi,
>
>> What kind of arguments do you need to pass? Each event function let you
>> access the IChartScriptContext, which gives you full access to the chart
>> model. (context.getChartInstance()).
>
>> More generally you can create an application context (IExternalContext)
>> and pass it in the build or prepare method when generating the chart.
>> This will then be available through
>> IChartScriptContext.getExternalContext(). This can be used to pass
>> runtime information to the event handler (for instance in a web app, you
>> could pass session variables).
>
>> Thanks,
>
>> David
>
>> "Erdal Karaca" <erdal.karaca@airbus.com> wrote in message
>> news:861691e1514e420fbf2ec93f818e664a$1@www.eclipse.org...
>>> Hi,
>>>
>>> I need to know whether it is possible to pass some arguments to a script
>>> event handler for a given chart object:
>>>
>>> Chart chart = ... any chart object
>>> chart.setScript( HistogramEventCallback.class.getName() );
>>>
>>> Setting the script for this chart this way makes it impossible to pass
>>> arguments to the executed HistogramEventCallback object without using
>>> any static (class) transfer attributes.
>>>
>>> Is there an elegant solution to this problem?
>>>
>>> I could write:
>>>
>>> //----
>>> class ChartGenerator {
>>>
>>> static Map< String, Object > chartProps = new HashMap< String, Object
>>> >();
>>>
>>> Chart createChart() {
>>> chartProps.put( "data-point-labels", new ArrayList< String >() );
>>> Chart chart = ... any chart object
>>> chart.setScript( HistogramEventCallback.class.getName() );
>>> // go on initializing the chart...
>>> }
>>> }
>>>
>>> class HistogramEventCallback extends ChartEventHandlerAdapter {
>>> public void beforeDrawDataPointLabel( DataPointHints dph, Label label,
>>> IChartScriptContext icsc ) {
>>> if ( ((List)ChartGenerator.chartProps.get(
>>> "data-point-labels" )).isEmpy() ) {
>>> // do something...
>>> }
>>> }
>>> }
>>>
>>>
>>> As I mentioned this is not elegant, since you have to deal with object
>>> synchronisation etc.
>>>
>>> Thanks!
>>>
>
>
|
|
| |
Goto Forum:
Current Time: Sat May 10 18:26:56 EDT 2025
Powered by FUDForum. Page generated in 0.03657 seconds
|