Skip to main content



      Home
Home » Archived » BIRT » Smart bar chart coloring
Smart bar chart coloring [message #123245] Thu, 02 February 2006 13:46 Go to next message
Eclipse UserFriend
I need to specify that bar(s) on a chart will change color whenever they
cross a marker value. How is this done (2.0)?
Re: Smart bar chart coloring [message #123455 is a reply to message #123245] Thu, 02 February 2006 16:07 Go to previous messageGo to next message
Eclipse UserFriend
Here is an example of script to change the color of a bar depending on its
value (in your case the value is the value of the marker). Select your
chart, go to the Script tab in the designer, then input this script. Change
the value 10 to the marker value, and the color to the one you want. If the
value of the marker can change, then you can access it through the chart
model, which is available from scriptContext (look at IChartScriptContext
Javadoc). Chart chart = scriptContext.getChartInstance();

function beforeDrawDataPointLabel(dataPoints, label, scriptContext)
{
val = dataPoints.getOrthogonalValue( );
clr = label.getCaption( ).getColor( );
if ( val < -10 ) clr.set( 32, 168, 255 );
else if ( ( val >= -10 ) & ( val <=10 ) ) clr.set( 168, 0, 208 );
else if ( val > 10 ) clr.set( 0, 208, 32 );
}

Thanks,

David

"Mark Lorenz" <lorenzm@labcorp.com> wrote in message
news:eed946222d15a1d310675f8418ea2fb7$1@www.eclipse.org...
>I need to specify that bar(s) on a chart will change color whenever they
>cross a marker value. How is this done (2.0)?
>
>
Re: Smart bar chart coloring [message #123978 is a reply to message #123455] Fri, 03 February 2006 13:30 Go to previous messageGo to next message
Eclipse UserFriend
It did not work (see my other append for details).

Also, here's what I found re: finding out the marker value:

chart.getAxes(); //EList??
orthogonalAxis.getMarkerLines(); //again, EList
val = marker.getValue().getValue(); //DataElement, then double value

That's the basics, but I'm not sure how to get between the steps (not set
up to step through the code - any suggestions?)

Thanks for the continuing help...M
Re: Smart bar chart coloring [message #124294 is a reply to message #123978] Fri, 03 February 2006 17:56 Go to previous messageGo to next message
Eclipse UserFriend
Try chart.getAxes().get(0).getMarkerLines().get(0).getValue().ge tValue();

David

"Mark Lorenz" <lorenzm@labcorp.com> wrote in message
news:b57d12d1188e6fb5ced06fd48ce3200b$1@www.eclipse.org...
> It did not work (see my other append for details).
>
> Also, here's what I found re: finding out the marker value:
>
> chart.getAxes(); //EList??
> orthogonalAxis.getMarkerLines(); //again, EList
> val = marker.getValue().getValue(); //DataElement, then double value
>
> That's the basics, but I'm not sure how to get between the steps (not set
> up to step through the code - any suggestions?)
>
> Thanks for the continuing help...M
>
Re: Smart bar chart coloring [message #124683 is a reply to message #124294] Mon, 06 February 2006 07:28 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the reply.

Here's what I tried:

chart = scriptContext.getChartInstance();
marker =
chart.getAxes().get(0).getMarkerLines().get(0).getValue().ge tValue();


and here's what resulted:

Feb 6, 2006 7:24:29 AM org.eclipse.birt.chart.exception.ChartException
logThis
SEVERE: Exception
org.eclipse.birt.chart.exception.ChartException: $NO-RB$ Wrapped
org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBounds Exception:
index=0, size=0 (<cmd>#10)
at
org.eclipse.birt.chart.model.ScriptHandler.callJavaScriptFun ction(ScriptHandler.java:724)
at
org.eclipse.birt.chart.model.ScriptHandler.callFunction(Scri ptHandler.java:1070)
at org.eclipse.birt.chart.render.Bar.renderSeries(Bar.java:1016 )
at
org.eclipse.birt.chart.render.AxesRenderer.renderPlot(AxesRe nderer.java:2175)
at
org.eclipse.birt.chart.render.AxesRenderer.render(AxesRender er.java:296)
at org.eclipse.birt.chart.factory.Generator.render(Generator.ja va:1207)
at
org.eclipse.birt.chart.reportitem.ChartReportItemPresentatio nImpl.onRowSets(ChartReportItemPresentationImpl.java:455)
at
org.eclipse.birt.report.engine.presentation.LocalizedEmitter .startExtendedContent(LocalizedEmitter.java:671)
at
org.eclipse.birt.report.engine.presentation.LocalizedEmitter .startForeign(LocalizedEmitter.java:447)
at
org.eclipse.birt.report.engine.executor.ExtendedItemExecutor .execute(ExtendedItemExecutor.java:101)
at
org.eclipse.birt.report.engine.executor.ReportExecutorVisito r.visitExtendedItem(ReportExecutorVisitor.java:81)
Re: Smart bar chart coloring [message #124820 is a reply to message #124683] Mon, 06 February 2006 10:32 Go to previous messageGo to next message
Eclipse UserFriend
I guess the marker is on the Y Axis. If so, you need to get the associated
axis: (this is assuming there is only one Y Axis)

chart.getAxes().get(0).getAssociatedAxes().get(0).getMarkerL ines().get(0).getValue().getValue();

Thanks,

David

"Mark Lorenz" <lorenzm@labcorp.com> wrote in message
news:b35b7072d8e122d8a123056444459c88$1@www.eclipse.org...
> Thanks for the reply.
>
> Here's what I tried:
>
> chart = scriptContext.getChartInstance();
> marker =
> chart.getAxes().get(0).getMarkerLines().get(0).getValue().ge tValue();
>
>
> and here's what resulted:
>
> Feb 6, 2006 7:24:29 AM org.eclipse.birt.chart.exception.ChartException
> logThis
> SEVERE: Exception
> org.eclipse.birt.chart.exception.ChartException: $NO-RB$ Wrapped
> org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBounds Exception:
> index=0, size=0 (<cmd>#10)
> at
> org.eclipse.birt.chart.model.ScriptHandler.callJavaScriptFun ction(ScriptHandler.java:724)
> at
> org.eclipse.birt.chart.model.ScriptHandler.callFunction(Scri ptHandler.java:1070)
> at org.eclipse.birt.chart.render.Bar.renderSeries(Bar.java:1016 )
> at
> org.eclipse.birt.chart.render.AxesRenderer.renderPlot(AxesRe nderer.java:2175)
> at
> org.eclipse.birt.chart.render.AxesRenderer.render(AxesRender er.java:296)
> at org.eclipse.birt.chart.factory.Generator.render(Generator.ja va:1207)
> at
> org.eclipse.birt.chart.reportitem.ChartReportItemPresentatio nImpl.onRowSets(ChartReportItemPresentationImpl.java:455)
> at
> org.eclipse.birt.report.engine.presentation.LocalizedEmitter .startExtendedContent(LocalizedEmitter.java:671)
> at
> org.eclipse.birt.report.engine.presentation.LocalizedEmitter .startForeign(LocalizedEmitter.java:447)
> at
> org.eclipse.birt.report.engine.executor.ExtendedItemExecutor .execute(ExtendedItemExecutor.java:101)
> at
> org.eclipse.birt.report.engine.executor.ReportExecutorVisito r.visitExtendedItem(ReportExecutorVisitor.java:81)
>
>
Re: Smart bar chart coloring [message #124832 is a reply to message #124820] Mon, 06 February 2006 10:39 Go to previous message
Eclipse UserFriend
It works! Thanks. For those that might benefit from this, here's how I
conditionally colored my bar chart based on a marker value:

function beforeDrawDataPoint( dataPointHints, fill, scriptContext ){
val = dataPointHints.getOrthogonalValue();
chart = scriptContext.getChartInstance();
marker =
chart.getAxes().get(0).getAssociatedAxes().get(0).getMarkerL ines().get(0).getValue().getValue();
if (val > marker) //crosses marker?
fill.set(255, 0, 0); //yes - display in red
else
fill.set(0, 0, 255); //no - display in blue
}
Previous Topic:What replaced the onStart(), onRow() and onFinish() scripting events
Next Topic:incomplete deployment error when BIRT gets deployed to JBOSS server
Goto Forum:
  


Current Time: Tue Jul 22 02:49:19 EDT 2025

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

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

Back to the top