How to get max Y value from StackedBarChart (jFreeChart)?

血红的双手。 提交于 2019-12-07 15:50:14

问题


How to get the maximum axis value from a created chart?

Here is how it is created:

final JFreeChart chart = ChartFactory.createStackedBarChart("", "", symbol, dataSet,PlotOrientation.VERTICAL, false, false, false);

I probably have to get the dataset from the chart and then get the maximum axis value from it. The dataset is DefaultCategoryDataset.


回答1:


Just iterate through the CategoryDataset

CategoryDataset dataset = createDataset();
for (int r = 0; r < dataset.getRowCount(); r++) {
    double max = Double.MIN_VALUE;
    for (int c = 0; c < dataset.getColumnCount(); c++) {
        Number number = dataset.getValue(r, c);
        double value = number == null ? Double.NaN : number.doubleValue();
        if (value > max) {
            max = value;
        }
    }
    System.out.println(dataset.getRowKey(r) + ": " + max);
}

Using the example dataset, produces the following output:

First: 5.0
Second: 8.0
Third: 6.0


来源:https://stackoverflow.com/questions/9996169/how-to-get-max-y-value-from-stackedbarchart-jfreechart

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