Home
Analytics
Layout HTML5 Bar Chart based on report parameter value
FreddyF
<p>Hey,</p><p> </p><p>im trying to set the color of my HTML5 bar chart based on the value of a report parameter.</p><p>I can change the color but i dont find a solution the get i changed based on the value of the parameter.</p><p> </p><p>This is the Script i use in the Client Script:</p><pre class="_prettyXprint _lang-js">beforeDrawDataPoint: function(point, pointOptions, chart, seriesIndex, pointIndex){var **** = ???var val1 = ****.getParameterValue("HTLPI");var val2 = ****.getParameterValue("LTLPI");if( point.y < val1 ) pointOptions.color = 'red';else if(point.y >= val1 && point.y < val2) pointOptions.color = 'yellow';else if(point.y >= val2) pointOptions.color = 'green';else pointOptions.color = 'blue';}</pre><p>The Part with the **** and ??? is the one i dont know how to handle!
Does anybody have an idea for a solution?</p><p> </p><p>kind regards</p><p>Freddy</p>
Find more posts tagged with
Comments
kclark
<p>I think in the HTML5 charts you still have access to icsc in beforeDrawDataPoint() so you'd do something like this</p><pre class="_prettyXprint _lang-">var val1 = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("HTLPI");</pre>
FreddyF
<p>Hey thank you for your fast answer! I change the code into this:</p><pre class="_prettyXprint _lang-js">beforeDrawDataPoint: function(point, pointOptions, chart, seriesIndex, pointIndex){var htlpi = icsc.getExternalContext().getScriptable().getParameterValue("HTLPI");var ltlpi = icsc.getExternalContext().getScriptable().getParameterValue("LTLPI");if( point.y < ltlpi ){ pointOptions.color = 'red';}else if(point.y >= ltlpi && point.y < htlpi){ pointOptions.color = 'yellow';}else if(point.y >= htlpi){ pointOptions.color = 'green';}}</pre><p>But their is noch change in the Color of the Bars. I think its because of this:</p><blockquote class="ipsBlockquote"><p> </p><p>function(point, pointOptions, chart, seriesIndex, pointIndex)</p></blockquote><p>Is there any other way to get the value of the report Parameter and it is possible to debug client scripting?</p><p> </p><p>kind regards</p><p>Freddy</p>
kclark
<p>Whenever I need to debug I usually run eclipse in console mode with eclipsec.exe. I also use Firebug. Between those two you should get most of the debugging information you'd need.</p><p> </p><p>Can you try this script?</p><pre class="_prettyXprint _lang-">function beforeDrawDataPoint(dph, fill, icsc){ var color = icsc.getExternalContext().getScriptable().getParameterValue("color"); if(color == "BLUE"){ fill.set(0,0,255); }}</pre>
FreddyF
<blockquote class="ipsBlockquote" data-author="kclark" data-cid="120163" data-time="1378914156"><div><p>Can you try this script?</p><pre class="_prettyXprint _lang-">function beforeDrawDataPoint(dph, fill, icsc){ var color = icsc.getExternalContext().getScriptable().getParameterValue("color"); if(color == "BLUE"){ fill.set(0,0,255); }}</pre></div></blockquote><p>In HTML5 charts you cant use the beforeDrawDataPoint(dph,fill,icsc) in the normal scripting function (the Support told me). Thats why i use the Client Script of the Chart. And this has only this parameters:</p><pre class="_prettyXprint _lang-">beforeDrawDataPoint: function(point, pointOptions, chart, seriesIndex, pointIndex)</pre><p>Thats whats in the BIRT Help is written:</p><p><img src='
http://www7.pic-upload.de/thumb/12.09.13/6zxzjea1wqt.png'
alt='Posted Image' class='bbc_img' /></p><p> </p><p>kind Regards</p><p>Freddy</p>
kclark
<p>In a text box above the chart you'll need to do something like this</p><pre class="_prettyXprint _lang-"><div id="mydiv" title="<VALUE-OF>params["color"]</VALUE-OF>" /></pre><p>And then use a script like this in your chart</p><pre class="_prettyXprint _lang-">beforeDrawDataPoint: function(point, pointOptions, chart, seriesIndex, pointIndex){ param = document.getElementById("mydiv").title; if(param == "Red") { pointOptions.color = "Red" }},</pre>
FreddyF
<p>Ok i understand the chart scripting but what do you mean in case of this?</p><p> </p><blockquote class="ipsBlockquote"><p> </p><p>[color=#000000;font-family:helvetica, arial, sans-serif;]In a text box above the chart you'll need to do something like this[/color]</p><pre class="_prettyXprint"><div id="mydiv" title="<VALUE-OF>params["color"]</VALUE-OF>" /></pre></blockquote>
kclark
<p>You'll want to drag a text item in your report and make sure it's above your chart so it gets ran before you're chart. From the drop down at the top of the text item you'll need to switch it from auto to html. That script will place the value of your parameter into a div so you can call it later in your chart.</p>
FreddyF
<p>Ok realy nice! It works! A little awkward but!
</p>
gustavomonarin
<p>Is the HTML5 chart part of the kleper release?</p>
FreddyF
<p>
@gustavomonarin
: I dont know i got it with birt designer PRO V3.7.2</p><p> </p><p>
@kclark
: Is it possible that HTML5 can not be executed from the JavaScript API? And is it possible to set the color with "pointOptions.color" in rgb or something else? Or are there only the preset colors?</p>
kclark
<blockquote class="ipsBlockquote" data-author="gustavomonarin" data-cid="120301" data-time="1379326971"><div><p>Is the HTML5 chart part of the kleper release?</p></div></blockquote><p> </p><p>No, HTML5 charts are in BRD Pro</p>