Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Change datapoint colour according to alternate series value
RayDR
Hi All,<br />
<br />
I want to highlight bars in a stacked bar graph according to a third series value. This means that I cannot use dph.getOrthogonalValue(). For example if my query looks like this:<br />
<br />
TYPE COUNT SIZE<br />
<br />
A 40 1.5<br />
A 10 2.2<br />
B 60 4.1<br />
<br />
I would like the bars grouped by type, bar size by count and the colour according to value. I tried adding an invisible series to the chart and adding this in the onRender event of the chart.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
i = 0;
diffSeries = [];
function afterDataSetFilled(series, dataSet, icsc)
{
if( series.getSeriesIdentifier() == "SIZE"){
diffSeries = dataSet.getValues();
}
}
function beforeDrawDataPoint(dph, fill, icsc)
{
if (Math.abs(diffSeries[i]) >= 2) {
fill.set(0,255,0);
};
i++;
}
</pre>
<br />
What I found is that the dataSet values are not ordered in the same way as the data points are rendered. Is there any way to change the fill colour by the "SIZE" value and draw the datapoint according to the "COUNT" value?<br />
<br />
I'm using BIRT 2.3.2.<br />
<br />
Thanks in advance.
Find more posts tagged with
Comments
mwilliams
Have you tried using the optional grouping for this? Maybe I'm misunderstanding the issue. Let me know.
RayDR
Hi Michael,
Apologies my example did omit the grouping field. The stacked bar chart would have TYPE as the x-axis, COUNT as the y value, a third field (let's call it MODEL) as the grouping field. What I'm hoping to do is highlight the datapoints by the SIZE field.
I understand that we will not be able to use the legend to see what MODEL group each datapoint belongs to, but that is fine in my situation.
Let me know if the above is clear or not.
Cheers.
mwilliams
If "size" is a field not used in the chart, you'd have to pass it into the chart, through script, most likely. If you have a way to associate the size with a field that does exist in the chart, you could probably use persistentGlobalVariables named after the chart field to pass the size values through. This would allow you to reference the size based on this other field that is in your chart. If you can provide a flat file of sample data and a design that uses it, to show me exactly what you're working with, I can probably help further.
RayDR
Hi Michael,<br />
<br />
Thanks for your help so far.<br />
<br />
Your suggestion sounds right but that's where I seem to come unstuck. Attached is a report example and flat file (it's a csv but I had to change the extension to upload it).<br />
<br />
You'll see in the file that startdate is the x axis, discount is the grouping, count is the y-value and I want to highlight according to discount_error.<br />
<br />
I want it to appear like a heat map where green is no error and red is a large error. This is the syntax I use to do that:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
discErr = //get the discount error
var red = Math.round(255*Math.min(discErr/50,1));
var green = Math.round(255 - 255*Math.max((discErr-50)/50,0));
fill.set(red,green,0);
</pre>
mwilliams
Take a look at this modified example. In the dataSet onFetch script, I create persistentGlobalVariables using the date and discount fields. In the chart script, I use the x-axis value and the series grouping values to recall these PGVs. From here, I use the discount error that was passed through the PGV to determine the red and green values. I had to add a little logic to your red expression to make sure it didn't go negative. I also had to pass a 0 for the values that had no discount error value. In the dataSet, I created computed columns for everything I did in script, just so I could see the values being used.
Hope this helps. Not sure if it's exactly right, but it should help get you there. Let me know if you have questions or issues.
RayDR
Perfect! Thanks that is exactly what I was after
mwilliams
Great! Glad to help! Let us know whenever you have questions!