JFreeChart BarChart-类别标记 [英] JFreeChart BarChart - Category Markers

查看:66
本文介绍了JFreeChart BarChart-类别标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个包含多个频带作为类别轴的条形图.我想做的是显示这些频段的可见分组:

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:

例如:

频率x1〜频率x2 =波段y(因此域轴具有类别x1,x1.1,x1.2到x2的值) 频率x3〜频率x4 =频段z(x3,x3.1 ..... x4)

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)

我想做的是在图形中显示Band Y和Band Z的标记.请注意,根据我可能获得的数据集,可能不会出现所有类别.假设在第一个示例中,我获得了x1到x1.6的值,因此带标记的范围是从x1到x1.6

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

我希望我能解释我的要求.在JFreeChart中这可能吗?如果是这样,我将如何实现这一目标?

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:

推荐答案

您的乐队对应于类别吗?如果可以,您可以使用CategoryMarker

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);

我不知道如何创建Mutli-CategoryMarker,但是您可以通过以下方式创建类似的东西 调整ItemMarginCategoryMargin并添加其他CategoryMarkers

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);
}

您可以创建一种添加多个标记的方法,例如

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

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

更正确的解决方案可能是编写您自己的Renderer和相关代码的实现

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

这篇关于JFreeChart BarChart-类别标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆