3


I have a followed the demo from JFreeChart (StackedBarChartDemo5) in order to create a plot allowing me to use the GroupedStackedBarRenderer.

Basically, I'm plotting air times for each station (represents a stack in a bar), connected to a radio (represents a bar in the plot), for both receive and transmit (RX and TX).
The plot looks something like this : enter image description here

There are two categories (RX and TX) and several groups (radios). As you can see, currently, the radio MACs are unreadable. I would like to rotate these labels, in order to make the plot legible.
I have used the following piece of code in order to try and rotate the labels: subCategoryAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4));
This only rotated the labels of the categories (RX and TX) instead of the labels of the groups (radio MACs): enter image description here

I have also tried several other approaches, all of which lead to nowhere... How do I rotate these sublabels?

Here is the underlying code that I used to populate the labels with :

SubCategoryAxis subCategoryAxis = new SubCategoryAxis("Radio MACs (separate Rx and Tx plots)");
subCategoryAxis.setCategoryMargin(0.05D);  

    // subCategoryAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4));

    KeyToGroupMap keyToGroupMap = null;
    final Set<String> radios = Sets.newHashSet();
    for (Entry<XRadio, Triplet<XStation, Double, Double>> entryMap: channelTimes.entries()) {
        final String radioMac = entryMap.getKey().getMac();
        if (keyToGroupMap == null)
            keyToGroupMap = new KeyToGroupMap(radioMac);

        if (!radios.contains(radioMac)) {
            subCategoryAxis.addSubCategory(radioMac);
            radios.add(radioMac);
        }

        final Triplet<XStation, Double, Double> chTriplet = entryMap.getValue();                           
        final String seriesKey = radioMac + ":" + chTriplet.a.getMac();
        keyToGroupMap.mapKeyToGroup(seriesKey, radioMac);                                
        model.getDataset().addValue(chTriplet.b, seriesKey, "Rx");
        model.getDataset().addValue(chTriplet.c, seriesKey, "Tx");
    }

    if (keyToGroupMap == null)
        return;

    groupedStackedBarRenderer.setSeriesToGroupMap(keyToGroupMap);                
    groupedStackedBarRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());      
    groupedStackedBarRenderer.setBaseItemLabelsVisible(true);                    
    groupedStackedBarRenderer.setItemMargin(0.1D); // 10 %
    groupedStackedBarRenderer.getPlot().setDomainAxis(subCategoryAxis);
StormLV
  • 31
  • 4
  • 1
    You may be able to use one of the approaches shown in [How do I rotate tick mark labels on the domain of a number axis in JFreeChart?](http://stackoverflow.com/questions/7071057/how-do-i-rotate-tick-mark-labels-on-the-domain-of-a-number-axis-in-jfreechart). – trashgod Aug 30 '11 at 14:23

1 Answers1

-1

You can set the rotation on the CategoryAxis in radians:

subCategoryAxis.setLabelAngle(-Math.PI / 2);

EDIT: It seems the SubCategoryAxis ignores rotation for sub-lables.

In the SubCategoryAxis#drawSubCategoryLabels method there is a call to TextUtilities.drawRotatedString() with angle=0.

Note: The examples are from 1.13.

The correct solution would be to make a patch that fixes the issue and submit said patch to the developers.

As for fixing it for your case, you could extend the SubCategoryAxis and call the TextUtilities.drawRotatedString() with the correct angle.

Jes
  • 2,748
  • 18
  • 22
  • I have already tried this, but all this does is rotates the label for the description of the axis (it rotates "Radio MACs (separate RX and TX plots)" – StormLV Aug 30 '11 at 11:31