java - 如何使用jfreechart计算折线图中添加的系列数?

标签 java jasper-reports jfreechart

我使用ireport设计了4个系列的折线图。我需要使用 jfreechart 在我的自定义类中计算这些系列

LineAndShapeRenderer lineAndShapeRenderer = new LineAndShapeRenderer();
lineAndShapeRenderer.setSeriesPositiveItemLabelPosition(0,new ItemLabelPosition(ItemLabelAnchor.CENTER,TextAnchor.TOP_LEFT));
lineAndShapeRenderer.setSeriesPositiveItemLabelPosition(1,new ItemLabelPosition(ItemLabelAnchor.INSIDE5,TextAnchor.TOP_LEFT));
lineAndShapeRenderer.setSeriesPositiveItemLabelPosition(2,new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,TextAnchor.BOTTOM_RIGHT));
lineAndShapeRenderer.setSeriesPositiveItemLabelPosition(3,new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1,TextAnchor.BOTTOM_LEFT));

我需要使用像 lineAndShapeRenderer.getSeriesCount();

而不是上面的硬编码

但我没有得到这样的方法或其他线索来设置如下

for (int i=0 ;i<lineAndShapeRenderer.getSeriesCount();i++)
    lineAndShapeRenderer.setSeriesPositiveItemLabelPosition(i,new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1,TextAnchor.BOTTOM_LEFT));

请帮我解决这个问题,以获得折线图中使用的系列数 - ire​​port。

最佳答案

您可以从用于创建图表的数据集中获取系列数。例如,CategoryDataset每个系列都有一行。你可以这样做:

int seriesCount = dataset.getRowCount();

编辑:在评论中,您说

categoryPlot.getLegendItems().getItemCount()…helped me to getting no. series used in line chart.

图例项是 View 的一部分;我想问一下型号。如果您有对绘图的引用,则可以获得对数据集的引用:

CategoryPlot categoryPlot = (CategoryPlot) chart.getPlot();
CategoryDataset dataset = categoryPlot. getDataset();
int seriesCount = dataset.getRowCount();

关于java - 如何使用jfreechart计算折线图中添加的系列数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42780343/

相关文章:

java - 使用字符串在java中查找类?

java - 为什么 html 内容不匹配一个相当简单的正则表达式?

java - 将字符串字段转换为集合以传递给子报表?

mysql - 如何在JSP中添加选择所有功能,例如日期从和到?

Java 中的 Java 多重比较

java - 为什么 new Something() 和 Something.class.newinstance() 之间没有明显的区别?

java - Jasper Reports 5.0.1 中的文件解析器

java - 如何将 jfree 图表作为小程序运行?

java - JFreeChart 的分层注释

java - 更改格式图例 Jfreechart