StackedBarChart row key is not added to DefaultCategoryDataSet

佐手、 提交于 2019-11-28 11:00:21

问题


I have two entity Classes: A and B. A has B entities, and I have a Map defined in the following format: Map<A, List<B>.

I want to add all map data to DefaultCategoryDataset with following code. For example, if have 5 A and each A has 4 B, I want to have 25 row keys. (A entity number * (A entityNumber + B entity number in each A). A Row key that stores A class must be same width; all other rows that store B entities must have same width. To succeed in this, I am giving the same values while adding A row keys((double) 1 / (1 + bResultList .size()), and giving smaller values while adding A row keys((double) 1 / (1 + bResultList .size() + 6).

DefaultCategoryDataset dataset = new DefaultCategoryDataset();
/** for each workpoint */
for (A aResult : map.keySet()) {
    List<B> bResultList = map.get(aResult);
    dataset.addValue(
        (double) 1 / (1 + bResultList.size()),
        "WorkPoint " + aResult.getTimeStep(),
        "WP T=" + aResult.getTimeStep());
    /** for each contingency result */
    for (B bResult : bResultList) {
        dataset.addValue(
            (double) 1 / (1 + bResultList.size() + 6),
            bResult.getName(),
            "WP T=" + aResult.getTimeStep());
    }
}

But when I add all map data to data set all row keys are not stored. When I debug, Dataset only has 9 rows. (A1,B1,B2,B3,B4,A2,A3,A4,A5) Only B entities of first A entity is stored as row keys. Other B entities of other A entity is not stored in database.

But when I display graph, all data is displayed in graph but in wrong order. Order is following.

A1-B1-B2-B3-B4
B1-B2-B3-B4-A2
B1-B2-B3-B4-A3
B1-B2-B3-B4-A4
B1-B2-B3-B4-A5

I want to display like

A1-B1-B2-B3-B4
A2-B1-B2-B3-B4
A3-B1-B2-B3-B4
A4-B1-B2-B3-B4
A5-B1-B2-B3-B4

回答1:


Absent your sscce the problem is not apparent. It may help to compare your data set to a typical CategoryDataset such as this one that has distinct series (row) and category (column) keys. Also, adding a CategoryItemLabelGenerator may aid debugging.

renderer.setBaseItemLabelGenerator(
    new StandardCategoryItemLabelGenerator(
        "{0} {1} {2}", NumberFormat.getInstance()));
renderer.setBaseItemLabelsVisible(true);


来源:https://stackoverflow.com/questions/8111244/stackedbarchart-row-key-is-not-added-to-defaultcategorydataset

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