Kiran
Kiran

Reputation: 366

Aligning data values vertically in JFreeChart bar chart

I have displayed values on top of bars in a JFreeChart bar chart. If there are lot of bars, values are getting too congested if the label is horizontal. I need to display the values vertically. I tried below options but they didn't work:

ItemLabelPosition itemLabelPositionTwo=new ItemLabelPosition(
    ItemLabelAnchor.OUTSIDE1, TextAnchor.BASELINE_RIGHT,TextAnchor.BASELINE_RIGHT,+90.0);

ItemLabelPosition itemLabelPositionTwo=new ItemLabelPosition(
    ItemLabelAnchor.OUTSIDE1, TextAnchor.BASELINE_RIGHT,TextAnchor.BASELINE_RIGHT,+45.0);

ItemLabelPosition itemLabelPositionTwo=new ItemLabelPosition(
    ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_RIGHT,TextAnchor.BASELINE_RIGHT,+45.0);

Any help on this very much appreciated.

enter image description here

I tried with Radians and below options. The maximum I was able to rotate is as below

ItemLabelPosition itemLabelPositionTwo=new ItemLabelPosition(
        ItemLabelAnchor.OUTSIDE6, TextAnchor.BASELINE_RIGHT,TextAnchor.BASELINE_RIGHT,-Math.PI/2);

    ItemLabelPosition itemLabelPositionTwo=new ItemLabelPosition(
        ItemLabelAnchor.OUTSIDE7, TextAnchor.BASELINE_RIGHT,TextAnchor.BASELINE_RIGHT,-Math.PI*2);
 ItemLabelPosition itemLabelPositionTwo=new ItemLabelPosition(
        ItemLabelAnchor.OUTSIDE8, TextAnchor.BASELINE_RIGHT,TextAnchor.BASELINE_RIGHT,Math.PI/2);

    ItemLabelPosition itemLabelPositionTwo=new ItemLabelPosition(
        ItemLabelAnchor.OUTSIDE9, TextAnchor.BASELINE_RIGHT,TextAnchor.BASELINE_RIGHT,+270.0);
 ItemLabelPosition itemLabelPositionTwo=new ItemLabelPosition(
        ItemLabelAnchor.OUTSIDE10, TextAnchor.BASELINE_RIGHT,TextAnchor.BASELINE_RIGHT,+360.0);

    ItemLabelPosition itemLabelPositionTwo=new ItemLabelPosition(
        ItemLabelAnchor.OUTSIDE1, TextAnchor.BASELINE_RIGHT,TextAnchor.BASELINE_RIGHT,+Math.PI/2);

enter image description here

Upvotes: 1

Views: 1099

Answers (2)

trashgod
trashgod

Reputation: 205785

The relevant ItemLabelPosition constructor expects the angle in radians; you probably want something like this:

ItemLabelPosition itemlabelposition = new ItemLabelPosition(
    ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, -Math.PI / 2);

bar chart

Upvotes: 2

diwakar gowda
diwakar gowda

Reputation: 1

Convert degrees to Radian and pass the converted value as parameter(angle) for ItemLabelPosition

ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,TextAnchor.BASELINE_CENTER,TextAnchor.BASELINE_CENTER,-1.5708); -- here 1.5708(Radian) is for 90°

Upvotes: 0

Related Questions