问题
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