Home
Analytics
Pie label positioning
b2tech
Hello:
Has anyone had success locating pie slice labels based off of the number of values provided in the dataset? For instance, six or less data points, locate the labels -inside- of the pie, with seven or more data points, locate the labels -outside- of the pie using leader lines. I want to do this inside the DE.
Any help would be greatly appreciated.
BillH
Find more posts tagged with
Comments
mwilliams
Are you designing your report with Java or with the designer?
b2tech
Java. Trying to make the change in beforeGeneration for example. I already drop unused series/legends in bar charts in that location based off of the provided data values.
I can't figure out how to get at the label "positioning" for a pie chart (inside/outside).
-- BillH
mwilliams
Try something like this:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
var numVals = 0;
function afterDataSetFilled( series, dataSet, icsc )
{
if(series.getSeriesIdentifier() == "Series 1"){
numVals = dataSet.getValues().length;
if(numVals > 6){
series.setLabelPosition(Position.OUTSIDE_LITERAL);
}
}
}
</pre>
b2tech
Great. Thanks, it now works.
Another question:
It appears that the legend in any 3D chart rendered has the colored boxes and individual legend text smashed up against each other which is NOT the case when you view a 3D chart from inside the BIRT Report Designer. The 3D box type legends should have the legend text placed with additional whitespace to separate the boxes from the actual text.
I believe I once saw someone comment about this. Is this a bug and how would you deal with it through code?
lerh.getLabel().getCaption().setValue(" " + slabel);
does not work as any leading spaces always get trimmed off. I tried to use "preserve whitespace" in the legend where slabel values were padded with 3 additional space characters but that just crashes out the chart.
BillH
mwilliams
Can you show a screenshot?
mogwai
<p>Hi Michael. Not sure if I can continue this thread or should start a new topic.</p><p>I need to do something similar, except that the code should put the label inside or outside the slice, depending on the slice size.</p><p>This means the same chart can have big slices with the label inside, and small slices with the label outside.</p><p>I have no idea how to do this. Any thoughts?</p>
mwilliams
<p>What's your BIRT version? I'm not sure this is possible since the label position is a series setting, but I'll try it out.
</p>
mogwai
<p>I upgraded to 4.2.3 although in the help screen it still says 3.7.1 which was my old version.</p>
mwilliams
<p>Do you mean 4.3.2? Or are you using BIRT Designer Professional (Its version is 4.2.3)?</p>
mogwai
<p>It must be 4.3.2 then since it is BIRT RCP. Difficult to tell when the help screen says 3.7.1
.</p>
mwilliams
<p>Interesting. The best way to tell will be to look at the xml source of a design and in the top couple lines, you'll see the version info. I'll check this out in 4.3.2, but I can't make any promises because it is a setting for the series and not for the individual points.</p>
mogwai
<p>In the XML it says 4.3.2. I will be grateful if you find a solution but if not, too bad. It would be a useful feature because putting the labels on the outside makes the chart small, particularly if the labels are long, whilst putting the labels inside makes the pie very crowded in the small slice areas. By rotating the pie with the small slices at the top or bottom and being able to put only those labels outside, you get the best of both worlds.</p>
mwilliams
<p>As expected, it doesn't seem like there's a way to change whether one point in the series has its label inside or outside. The only way I could think to do it would be very hacky and would involve messing with the insets of the labels to move them. I can only imagine the mess that would be. You could always file an enhancement request for something like this in the bugzilla in the community section of the eclipse.org/birt site. I can definitely see value in the labels being able to work like this for the pie chart. If you do post a request, please post the info in here for future reference.</p>