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)
Using Patterns for Charts
kiranvspt
<p>Hi,</p>
<p> </p>
<p>I am new to BIRT design and I am using iHub to design BIRT reports. I want to use chart script to apply patterns for bars in the chart. </p>
<p> </p>
<p>When I searched in the internet for apply patterns to charts using scripting,I found this can be achieved using the class <strong>org.</strong><span style="color:rgb(51,51,51);font-family:Verdana, Arial, sans-serif;font-size:13px;"><strong>eclipse.birt.chart.model.attribute.impl.PatternImageImpl</strong>. But I did not get sample code how to use this class.</span></p>
<p> </p>
<p>Could you please help to write script for applying patterns for bars in chart using chart script?</p>
<p> </p>
<p>Thanks in advance!</p>
Find more posts tagged with
Comments
pricher
<p>Hi,</p>
<p> </p>
<p>If you are creating charts with output formats such as PNG, JPG, BMP, or SVG, you do not need scripting to create patterns. For the Series Palette, you will find a button at the bottom to define a pattern that can be applied to your charts.</p>
<p> </p>
<p>Upon choosing this option, you will be able to select from a list of pre-defined pattern, or even create your own custom pattern.</p>
<p> </p>
<p>Hope this helps,</p>
<p> </p>
<p>P.</p>
kiranvspt
<p>Hi Pricher,</p>
<p> </p>
<p>Thank you so much for your reply. We have a requirement to represent chart results with different patterns depends on the values. For example if the value is between 1-100 then represent the graph bar with one pattern and if 100-200 with different pattern etc.,. I guess we can achieve this by using script only.</p>
<p> </p>
<p>So, it will be helpful for me if we have any sample code applying patterns to charts using script.</p>
<p> </p>
<p>Thanks,</p>
pricher
<p>Hi,</p>
<p> </p>
<p>Attached is an example that uses chart scripting to change dynamically the pattern of a bar in a chart based on its value.</p>
<p> </p>
<p>First, you need to define patterns in the Series Palette of the chart. In the example, I have defined 3 patterns, one for each of the first 3 series.</p>
<p> </p>
<p>There are two methods overridden in the chart. In beforeGeneration, I get a list of all the entries defined in the Palette. The first 3 entries of that list are PatternImageImpl objects.</p>
<p> </p>
<p><span style="font-family:'courier new', courier, monospace;">function beforeGeneration( chart, icsc )<br>
{<br>
importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);<br><br>
// Store the palette definition entries<br>
xAxis = chart.getAxes().get(0);<br>
sd = xAxis.getSeriesDefinitions().get(0);<br>
sp = sd.getSeriesPalette();<br>
entries = sp.getEntries(); <br>
}</span></p>
<p> </p>
<p>In beforeDrawDataPoint, I test on the value of the bar (y-axis value) to determine which pattern to display.</p>
<p> </p>
<p><span style="font-family:'courier new', courier, monospace;">function beforeDrawDataPoint( dph, fill, icsc )<br>
{<br>
importPackage( Packages.org.eclipse.birt.chart.model.attribute.impl );<br><br>
//Get the value of the bar being displayed<br>
val = dph.getOrthogonalValue();<br><br>
// Test to see if the series being displayed is of type PatternImageImpl<br>
if( fill.getClass().isAssignableFrom(PatternImageImpl)){<br>
<br>
// Test on the value to decide which pattern to display<br>
// The fill is reset by reading the bitmap from one of the 3 patterns defined in the palette<br>
if (val > 2000){<br>
fill.setBitmap(entries.get(0).getBitmap());<br>
}<br>
else if (val < 1000) {<br>
fill.setBitmap(entries.get(1).getBitmap());<br>
}<br>
else {<br>
fill.setBitmap(entries.get(2).getBitmap());<br>
}<br>
}<br>
}</span><br>
</p>
<p>Hope this helps,</p>
<p> </p>
<p>P.</p>
<p> </p>
<p> </p>