How to count the number of series of a bar chart in JFreeChart?

谁都会走 提交于 2019-12-08 08:50:48

问题


I am facing the some problems when creating bar chart using JFreeChart. I have to write a condition according to a number of series available on the bar chart, but I don't know how to get it.


回答1:


Bar charts typically use a CategoryDataset, all of which implement the KeyedValues2D interface. Use dataset.getRowCount() to get the number of series. Use dataset.getColumnCount() to get the number of distinct categories. Their product is the total number of bars.

As a concrete example, I added a spurious new series to BarChartDemo1 to get three series (rows) and two categories (columns).

private static CategoryDataset createDataset() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    …
    dataset.addValue(8000, "Meretricious", "Warm-up");
    dataset.addValue(24000, "Meretricious", "Test");
    return dataset;
}



来源:https://stackoverflow.com/questions/37671080/how-to-count-the-number-of-series-of-a-bar-chart-in-jfreechart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!