如何计算JFreeChart中条形图的系列数? [英] How to count the number of series of a bar chart in JFreeChart?
问题描述
使用JFreeChart
创建条形图时,我遇到了一些问题.
我必须根据条形图上可用的多个序列来编写条件,但我不知道该如何获得.
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.
推荐答案
条形图通常使用 KeyedValues2D
接口.使用dataset.getRowCount()
获取序列号.使用dataset.getColumnCount()
获取不同类别的数量.他们的乘积就是条的总数.
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;
}
这篇关于如何计算JFreeChart中条形图的系列数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!