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)
Draw a bar chart as shown in the attached image
Tony Hsiao
Hi, I just want to draw a bar chart which looks like the one shown in the attached image, any advice?
Thanks in advance!
Find more posts tagged with
Comments
Tony Hsiao
Hi, I just want to draw a bar chart which looks like the one shown in the attached image, any advice?
Thanks in advance!
mwilliams
What about the chart are you having trouble achieving?
Tony Hsiao
Well, thanks for your reply!
I'm not quite familiar with BIRT, to achieve the goal in my eclipse plugin, I have tried two approachs:
(1)xAxis.setType(AxisType.TEXT_LITERAL);
xAxis is the object which stands for the x axis. But how can I put the tick label (the number) exactly below the tick other than between two adjacent ticks. Moreover, there would be one more tick label for the first or the last tick, how to achieve it?
(2)xAxis.setCategoryAxis(false);
xAxis.setType(AxisType.LINEAR_LITERAL);
In this case, the tick label is below the tick, however, the bar is drawed above a tick, how can I move it to the midpoint of the two adjacent ticks.
I hope I have made my troubles clear, and look forward to your reply, thank you!
mwilliams
Yeah. The label will always be under the bar, out of the box. As you've stated, with a category axis, the bar and label are between ticks and with a non category axis, they're both on the tick. You could shift the labels with the insets, but I don't know that there would be an exact science to this if your number of bars change. You could get the extra tick by modifying the chart data in script to add an extra bar, but just give it a 0 value.
Tony Hsiao
Thank you so much, mwilliams!
So, to shift the label from between two ticks to under one tick, I need the extent between two adjacent ticks, how could ?get it?
mwilliams
Try adjusting the left or right inset on the label. If you have a dynamic number of bars, this will require script to try to set this up perfectly.
To find the inset setting, open the chart editor, go to the format chart tab, go to the x-axis section, and click on the label button.
Tony Hsiao
Sorry for not replying to you for so long, I'm so busy for the past month that I couldn't spare time to handle the problem
!
So, I adjusted the right inset on the label in my eclipse plugin through the following statement:
xAxisPrimary.getLabel().getInsets().setRight(45);// xAxixPrimary is an object of class Axis
I need your help to solve the following two problems:
(1)I paint the chart in a composite which may be resized in my eclispe plugin, so I need to know the the extent between two adjacent ticks so that I could pass half of the value as the parameter of setRight(double) method.
(2)After I added the above statement, the tick labels were successfully shifted to under the tick, while some tick labels disappear, I'm not sure why this happened.
Looking forward to your reply, thank you!
mwilliams
Any way you can create a sample that uses the sample database or data with which I can run the report that will show what you've got so far? This way, we can work with the same design so we see the same things.
Tony Hsiao
Thank you for your reply, mwilliams! The attached java file is the java class to create a bar chart and the image is the screenshot of the program. I have four tick labels while only two show up, which really upsets me. Another thing, instead of adding an extra bar whose value is put to 0, does it has other ways to add an extra tick label under the last tick?
mwilliams
What version of BIRT are you using?
Tony Hsiao
4.2.2. I installed birt-report-framework-sdk-4_2_2 into my eclipse SDK.
mwilliams
Hmm. That's the version of BIRT I tried to run it in. I get a nullpointer exception. I'm sure I'm just missing a dependency of some sort. It's not one used directly in the Java file cause there are no errors or warnings within the Java project.
Tony Hsiao
I hope the attached screenshot can do some help.
mwilliams
Got it running.
Changing
xAxisPrimary.getLabel().getInsets().setRight(45);
to
xAxisPrimary.getLabel().getInsets().setLeft(-45);
seems to solve the missing label issue.
So, that's a start.
Tony Hsiao
So, the missing labels are back, thank you, mwilliams!
Well, I need your help for another question. In my actual program, the number of bars is not fixed, it may be changed, then the hard-coded parameter -45 wouldn't work well if the number of bars is changed, so how can I determine the paramter passed to the method setLeft(****) in my program? I'm not sure if it makes sense to pass half of the distance between two adjacent ticks as the paramter, if it does, then how can I get the distance between two adjacent ticks?
Looking forward to your reply, thank you!
mwilliams
In some testing in a chart in the designer, this script was able to move the labels to the correct spot no matter how many bars there were:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
firstDPX = null;
secondDPX = null;
function beforeDrawDataPoint( dph, fill, icsc )
{
if(firstDPX == null){
firstDPX = dph.getLocation().getX();
}
else if(secondDPX == null){
secondDPX = dph.getLocation().getX();
}
}
function beforeDrawAxisLabel( axis, label, icsc )
{
labelSpacing = secondDPX - firstDPX;
leftInset = labelSpacing/1.4 * -1;
label.getInsets().setLeft(leftInset);
}
</pre>
<br />
You could try something similar within your code. It should work. Let me know.