2

I'm creating a BarChart that contains multiple frequency bands as the category axis. What I want to do is to show a visible grouping of these frequency bands:

For example:

Freq x1 ~ Freq x2 = Band y (so the domain axis has values for category x1, x1.1, x1.2 till x2) Freq x3 ~ Freq x4 = Band z (x3, x3.1 .....x4)

What I want to do is show markers for Band Y and Band Z in the graph. Note that based on the dataset that I may get, not all categories may be present. Say, for the 1st example, I've got values for x1 to x1.6 and so the band marker would be from x1 till x1.6

I hope I could explain my requirement. Is this possible in JFreeChart? If so, how may I go about achieving this?

Just to clarify a little more, here's a picture of something that I want to achieve: enter image description here

Sujay
  • 6,753
  • 2
  • 30
  • 49

1 Answers1

4

Do your Bands corresponded to Categories? If they do you can use a CategoryMarker

CategoryMarker marker = new CategoryMarker("Category 3");
marker.setLabel("Band Y");
marker.setPaint(Color.red);
marker.setOutlinePaint(Color.red);
marker.setAlpha(0.5f);
marker.setLabelAnchor(RectangleAnchor.TOP);
marker.setLabelTextAnchor(TextAnchor.TOP_CENTER);
marker.setLabelOffsetType(LengthAdjustmentType.CONTRACT);
plot.addDomainMarker(marker, Layer.BACKGROUND);

Bar Chart With CategoryMarker

I can't work out how to create a Mutli-CategoryMarker but you can create something similer by adjusting the ItemMargin and CategoryMargin and adding additional CategoryMarkers

{
  CategoryMarker marker = new CategoryMarker("Category 2");
  marker.setLabel("Band X");
  marker.setLabelAnchor(RectangleAnchor.TOP);
  marker.setLabelTextAnchor(TextAnchor.TOP_CENTER);
  marker.setLabelOffsetType(LengthAdjustmentType.CONTRACT);
  plot.addDomainMarker(marker, Layer.BACKGROUND);
  }
  {
  CategoryMarker marker = new CategoryMarker("Category 3");
  plot.addDomainMarker(marker, Layer.BACKGROUND);
  }
  renderer.setItemMargin(0.0);
  CategoryAxis axis = plot.getDomainAxis();
  axis.setCategoryMargin(0);
}

enter image description here

You could create a method to add multiple markers e.g

private void addMarkers(List<Comparable> keys){
...

A more correct solution may be to write your own implementation of the Renderer and accociated code

GrahamA
  • 5,875
  • 29
  • 39
  • Thanks for your answer! Yes, my bands correspond to a set of categories...say band#1 = {category1....category4}, band#2 = {category5.....category8} and so on. I understand, that by extension of this solution, I can add a category marker to each category individually but would be possible to define a set of categories corresponding to a band? – Sujay Jul 09 '12 at 13:48