Highlighting topN in bar chart
I have a bar chart showing 10 bars. I would like to give the 3 longest bars (i.e. the 3 bars with the highest value) a different colour then the other bars.<br />
<br />
I have found an example online (<a class='bbc_url' href='http://marklorenz.blogspot.com/2006/02/birt-tips-for-java-developers.html'>http://marklorenz.blogspot.com/2006/02/birt-tips-for-java-developers.html</a>) that shows how to change the colour of a bar if it passes a marker line, but have been struggeling to adapt this to my wishes. <br />
<br />
Example I found:<br />
<br />
function beforeDrawDataPoint(dataPointHints, fill, scriptContext )<br />
{ val = dataPointHints.getOrthogonalValue();<br />
chart = scriptContext.getChartInstance();<br />
marker = chart.getAxes().get(0).getAssociatedAxes().get(0).getMarkerLines().get(0).getValue().getValue(); <br />
if (val > marker) //crosses marker?<br />
fill.set(255, 0, 0); //yes - display in red <br />
elsefill.set(0, 0, 255); //no - display in blue<br />
}<br />
<br />
Which function should I use in a script attached to a chart to test whether a value is in the Top 3 ?<br />
<br />
I have tried things like: if (isTopN(val, 3)....<br />
<br />
but keep getting errors that isTopN is undefined.<br />
<br />
Any help would be greatly appreciated.
<br />
I have found an example online (<a class='bbc_url' href='http://marklorenz.blogspot.com/2006/02/birt-tips-for-java-developers.html'>http://marklorenz.blogspot.com/2006/02/birt-tips-for-java-developers.html</a>) that shows how to change the colour of a bar if it passes a marker line, but have been struggeling to adapt this to my wishes. <br />
<br />
Example I found:<br />
<br />
function beforeDrawDataPoint(dataPointHints, fill, scriptContext )<br />
{ val = dataPointHints.getOrthogonalValue();<br />
chart = scriptContext.getChartInstance();<br />
marker = chart.getAxes().get(0).getAssociatedAxes().get(0).getMarkerLines().get(0).getValue().getValue(); <br />
if (val > marker) //crosses marker?<br />
fill.set(255, 0, 0); //yes - display in red <br />
elsefill.set(0, 0, 255); //no - display in blue<br />
}<br />
<br />
Which function should I use in a script attached to a chart to test whether a value is in the Top 3 ?<br />
<br />
I have tried things like: if (isTopN(val, 3)....<br />
<br />
but keep getting errors that isTopN is undefined.<br />
<br />
Any help would be greatly appreciated.
0
Comments
-
Hi Mennovh,
If it's possible to do with your data. You could sort it by the column that has the values you are charting and put in a loop in the onRender script section of the chart to change the color of the first N bars. I'll try a couple things to see if I can figure out how to highlight the top N without sorting the data.
Regards,
MichaelWarning No formatter is installed for the format ipb0 -
i also need to highlight / conditional <strong class='bbc'>color the top n results in a bar chart</strong>.<br />
so i tried the solution described about from mark lorenz blog.<br />
but unfortunatly it's not working with birt 2.2 any more <strong class='bbc'>because the fill object doesn't have a method .set </strong>anymore.<br />
<br />
<strong class='bbc'>error msg:</strong><br />
TypeError: Cannot find function set. at line 20 of chart script: ...<br />
<br />
<strong class='bbc'>script is used:</strong><br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
/**
* Called before drawing each datapoint graphical representation or marker.
* @param dph DataPointHints
* @param fil Fill
* @param icsc IChartScriptContext
*/
function beforeDrawDataPoint(dph, fill, icsc)
{
val = dph.getOrthogonalValue();
chart = icsc.getChartInstance();
marker = chart.getAxes().get(0).getAssociatedAxes().get(0). getMarkerLines().get(0).getValue().getValue();
if (val > marker) //crosses marker?
[B]fill.set(255,0,0)[/B]; //yes - display in red
else
fill.set(0,0,255); //no - display in blue
}
</pre>0 -
Mennovh and Indie,<br />
<br />
I just posted a DevShare example on one way to highlight the top N values of a bar chart. Hope it helps. Here is the link:<br />
<br />
<a class='bbc_url' href='http://www.birt-exchange.com/modules/wfdownloads/singlefile.php?cid=2&lid=401'>http://www.birt-exchange.com/modules/wfdownloads/singlefile.php?cid=2&lid=401</a><br />
<br />
Regards,<br />
<br />
Michael WilliamsWarning No formatter is installed for the format ipb0
Categories
- All Categories
- 108 Developer Announcements
- 53 Articles
- 106 General Questions
- 144 IM Services
- 43 OpenText Hackathon
- 32 Developer Tools
- 20.6K Analytics
- 4.1K AppWorks
- 8.9K Extended ECM
- 899 Cloud Fax and Notifications
- 77 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 120 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management