Home
Analytics
BIRT 2.3.2 Charts - changing the colors for Bar chart depend on specific value
Saed
Hi all,<br />
<br />
I'm trying to change the colors for bars & legends for bar chart, I read some articles about how to change the colors using on 'beforeDrawDataPoint':<br />
<em class='bbc'><br />
var Condition = dph.getBaseDisplayValue();<br />
if(Condition.contains("Critical")) { fill.set(255, 0, 0);} // Set to RED<br />
else if(Condition.contains("High")){ fill.set(255, 255, 0); } // Set to Yellow</em><br />
<br />
but the issue is I faced the following exception when I generate the report, it is seems like the fill.set() function not exist on BIRT ( I'm using<strong class='bbc'> BIRT 2.3.2</strong>), please advice if there is any solution for this issue or any other way to change the colors<br />
<br />
The exception is :<br />
<br />
- TypeError: Cannot find function set. at line 105 of chart script:'' <br />
exception.javascript.error ( 1 time(s) )<br />
detail : org.eclipse.birt.report.engine.api.EngineException: TypeError: Cannot find function set. at line 105 of chart script:'' at org.eclipse.birt.report.engine.executor.ExecutionContext.addException(ExecutionContext.java:1121) at org.eclipse.birt.report.engine.presentation.LocalizedContentVisitor.processExtendedContent(LocalizedContentVisitor.java:933) at org.eclipse.birt.report.engine.presentation.LocalizedContentVisitor.visitForeign(LocalizedContentVisitor.java:501) at org.eclipse.birt.report.engine.content.impl.ForeignContent.accept(ForeignContent.java:69) at org.eclipse.birt.report.engine.presentation.LocalizedContentVisitor.localize(LocalizedContentVisitor.java:150) at org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:36) at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:63) at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:90)<br />
......<br />
<br />
Thanks in advance.
Find more posts tagged with
Comments
pricher
Hi Saed,
In your script, you are using the "contains" method on the string Condition. But there is no such thing as a "contains" method in a Javascript string! Although the compiler should have picked up that error, it is erroneously pointing to the fill.set() method.
You can replace the "contains" method with "indexOf", something like:
if(Condition.indexOf("Critical") >= 0)
Hope this helps,
P.
Saed
Hi pricher,
thanks for your replay, I tried to use only fill.set() function as bellow and the same exception happened when generating a report,
function beforeDrawDataPoint( dph, fill, icsc )
{
fill.set(255, 0, 0);
}
regards,
Saed
pricher
Can you send your report design?
Saed
Hi pricher,
sorry but I can't share my rptdesign, but we can talk about this example :
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1231-custom-chart-colors-based-on-data-set-values/
it is give me the same exception which I mentioned before!
also I need to change the colors to Gradient Color so I think there is another way to do it, if you have an idea about how BIRT handle Gradient Colors in chart script.
Thanks,
Saed
Saed
any update please ?
pricher
Hi Saed,
Sorry for the later reply...
I have not been able to replicate the problem you have with the code example you downloaded. I am also running BIRT 2.3.2, so we can discount a version problem. In any case, I am re-sending you the same example you have downloaded, plus some added script to change the gradient colors through script. Please note that in order for the setStartColor, setEndColor, setDirection, and setCyclic methods to work on the Fill object, you need to go in Format Chart --> Series --> Series Palette and change the default color of the series you displayed to gradient colors. In my example, I only changed the first series. The code in the script could also be improved...
Hope this helps,
P.
Baku
I have exactly the same issue, but using BIRT 2.6.<br />
The report you uploaded with the 2 pie chart works (with the fill.set method), but if I build a new report, and I try a fill.set(255,255,0) there is this error :<br />
<br />
Cannot find function set in object org.eclipse.birt.chart.model.attribute.impl.PatternImageImpl@1f32f91f (type: <unset>) (uRL: null) (bitmap: 35184372350976)<br />
<br />
<br />
The fill object only have setType(int) method...<br />
<br />
<strong class='bbc'>*Edit*</strong><br />
<br />
Even if the fill.set method seems to not exist (intellisense does not show it), it works for a PIE CHART.<br />
But I need to change the color of a serie in a Gantt chart, and don't know how to it.
dicedpeppa
Hi I had a that very same problem. I could change the color of the chart, but no matter what script I tried to change the legend, I was getting the error message saying it could not find the "set" function I was calling (Cannot find function set in object).
Struggled with that for a while until I decided to delete the default series palette colours (+ an extra couple of colour sets I thought were pretty ugly). Tried running the report again, containing the script to set the fill for the legend. It worked! Why? No idea. All I know is that before I determined the colour using scripts I had been messing around with the gradients, negative colours etc through the UI.Maybe not much help, but I thought I'd share this anyway.